Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

repository

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:

  • modified: file1.cpp
  • modified: file2.cpp
  • modified: file1.h
  • modified: file2.h

Untracked files:

  • file3.cpp
  • file3.h
  • dontAddMe.blah
  • dontAddMeEither.foo

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

like image 610
TheGrapeBeyond Avatar asked Mar 15 '23 05:03

TheGrapeBeyond


1 Answers

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.

like image 51
Chris Avatar answered Mar 17 '23 05:03

Chris