TheGrapeBeyond
TheGrapeBeyond

Reputation: 563

Stage files with specific extension, and only those that show as modified in git status

In git on the command prompt, I would like to simply add *.cpp and *.h files, but ONLY those that are showing up as modified, when I run the command git status.

For example, if, after I run the command git status I get:

Changes not staged for commit:

Untracked files:

Then I want to stage everything, (all the cpps and h files), except for the last two. How do I do that? Thanks

Upvotes: 5

Views: 2531

Answers (1)

Chris
Chris

Reputation: 136880

Use git add's -u option in conjunction with whatever other options you want:

-u
--update

Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.

In this case, something like git add -u '*.cpp' '*.h' should do what you want.

Upvotes: 8

Related Questions