I'm trying to export the file names of the files that were changed through commits in git to a txt file. How can I approach this problem? I just want the file name and I would like one file name on each line instead of all of them clumped together. Thank you in advance for the help!
Asked
Active
Viewed 771 times
2 Answers
3
Update: shorter / simpler version (no need for log -1
here when you have show
)
git show --pretty="" --name-only <commitHash> > file.txt
Original answer
git log --name-only <commitHash> -1 --pretty=format:'' > file.txt
will list the related files for any given commit, and print the list, one file per line, in file.txt
. (doc)
Note that you could also filter the type of operation relevant for the listing here. I mean, you could list only modified files, or deleted files, for example.

Romain Valeri
- 19,645
- 3
- 36
- 61
-
Some constructive criticism for the downvote? I don't mind the rep, just want to improve on a mistake if any :-) – Romain Valeri Mar 22 '19 at 18:49
-3
Thanks for correction by RomainValeri. My command just made a little modification, it shows file names by date order:
git log -1 --date-order --name-only --pretty=format:'' > myAllCommittedFiles.txt

muhammad tayyab
- 727
- 7
- 18
-
Did you actually *try* any of these commands in a terminal? OP wants a list of the files, one per line, without extra info. I'm pretty sure that you're outputting way too much things here... – Romain Valeri Mar 22 '19 at 22:15
-
git log --date-order --pretty=oneline --name-only > myAllCommittedFiles.txt this does what's the issue? – muhammad tayyab Mar 22 '19 at 23:05
-
No, this outputs commit hashes also. try it in any repo, you'll see for yourself. – Romain Valeri Mar 22 '19 at 23:07
-
-
Hmm... that's odd. Let's check versions, it must be something they changed in the output format at some point. `git version 2.21.0.windows.1` for me. You? – Romain Valeri Mar 22 '19 at 23:09
-
-
1I'm not "winning" anything. Here I've been on your team all along. And Brian too. We're all together against ignorance. – Romain Valeri Mar 23 '19 at 05:28