1

I know if I want to get the list of all committed files in a particular commit if I know the commit hash or relative position from HEAD I can get the list of files using

git show --stat <commit-id> --names-only

or

git show --stat HEAD~n --names-only

but if I want to get list of all the files that have been committed till now since the first commit, how can I get them.

One possible way I can think of is to write a bash script ( or bash command) to loop over all the commits and run above command but I wanted to ask if there is any git way to achieve this thing?

CodeTalker
  • 1,683
  • 2
  • 21
  • 31

1 Answers1

1

I want to get list of all the files that have been committed till now since the first commit

You could do a git diff between:

  • the empty tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
  • a given commit SHA1

That is:

git diff --name-only 4b825dc642cb6eb9a060e54bf8d69288fbee4904 <SHA1>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It works indeed. Thanks to you that I added this `the empty tree` thing to my knowledge. I was never aware of it. – CodeTalker Apr 16 '20 at 05:20
  • 1
    @CodeTalker Yes, the empty tree is neat, and will soon evolve when Git will use SHA2 (it will be `6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321`) – VonC Apr 16 '20 at 05:23
  • yes, I saw your post on the link provided above under `the empty tree` regarding SHA2. Also, apart from it, I am amazed to look at your profile, you are one of the giant knowledge base on Stackoverflow. I am happy to found you today. I am gonna follow you to gain more knowledge from you :) – CodeTalker Apr 16 '20 at 05:29
  • @CodeTalker I post mainly on Git these days, and the others contributors (https://stackoverflow.com/tags/git/topusers) are generally way better than me, starting with torek (https://stackoverflow.com/users/1256452/torek) who, incidentally, asked about the empty tree back in 2012. – VonC Apr 16 '20 at 05:32