I'm using git diff --name-status
to track which files have been modified/added/removed/renamed/copied between two commits, and it works great.
Now suppose I move file file1
to newdir/file1
, commit, and then run git diff, I get this:
$ git diff --name-status -C HEAD~1 HEAD
R100 file1 newdir/file1
Is there a way to ask git to limit itself to the list of changes inside a given directory but not its children? I'd like to know the exact changes both for the root directory and for the newdir
directory, separately. For newdir
, it's easy:
$ git diff --name-status -C HEAD~1 HEAD -- newdir
A newdir/file1
… but how can I obtain the "complementary" diff info in the root directory? I.e., this output:
$ git diff ???
D file1
Note that I want to keep the -C
option to detect renames and copies inside the same directory.
Pass it through to grep:
git diff --name-status HEAD..HEAD~1 . | grep ^[^/]*$
This will filter out anything that contains a sub directory, if you need to get something from a deeper do this:
git diff --name-status HEAD..HEAD~1 <path> | grep ^<path>[^/]*$
You could easily alias this if you wanted to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With