Andrius
Andrius

Reputation: 21188

git - show modified files, except for deleted (or renamed) files

I was using this git command to show modified files:

git diff-index --name-only --cached HEAD

It does show files modified, but I need it to make diff output ignore files that no longer exist (that they were either deleted or renamed).

For example let say I rename file test.py to test2.py. Running command above would show:

test.py test2.py

But output needs to be only: test2.py

P.S. I'm using this information to run checks on those files that were modified (edited or added). But I did not think about when files are renamed or removed. My used command will still show those files, but my checks will fail, because those files no longer exist and no checks should be run on them in a first place.

Upvotes: 3

Views: 1027

Answers (1)

OliverRadini
OliverRadini

Reputation: 6466

You can use --diff-filter=dr to exclude delete files when doing the diff docs

*Edit: Thanks to @RomainVALERI for pointing out the r option for renamed

Upvotes: 5

Related Questions