1
git show -m -1 --name-only --pretty=format: --stat --relative --first-parent commit_id

I am using above command to list all the files in a commit. It is listing all the deleted files as well.

I want to remove deleted files from my list.

Is there a way to exclude deleted files from git show command?
Or is there a way to list deleted files from a commit id?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Asma
  • 99
  • 9

1 Answers1

0

Check first if adding the --diff-filter option of git show helps

--diff-filter=ACMRTUXB

So anything but "D", which would filter for deleted files.

Shorter version (since Git 1.8.5):

 --diff-filter=d

The lowercase "d" means: everything but deleted files.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • git show command with --diff-filter=d is not working with specific commit id – Asma Jan 28 '20 at 06:54
  • @Asma I just tested it on https://github.com/git/git/commit/4d924528d8bfe947abfc54ee9bd3892ab509c8cd: `git show --diff-filter=D --name-only --oneline 4d924528d8bfe947abfc54ee9bd3892ab509c8cd` does list the deleted file. With 'd', it does list the other added or modified files. – VonC Jan 28 '20 at 06:59
  • @Asma With your command, it does work: `git show -m -1 --name-only --pretty=format: --stat --relative --first-parent --diff-filter=d 4d924528d8bfe947abfc54ee9bd3892ab509c8cd` – VonC Jan 28 '20 at 07:00