I am looking for a simple git
command that provides a nicely formatted list of all files that were part of the commit given by a hash (SHA1), with no extraneous
There's also git whatchanged
, which is more low level than git log
NAME
git-whatchanged - Show logs with difference each commit introduces
It outputs the commit summary with a list of files beneath it with their modes and if there added(A
), deleted(D
) or modified(M
);
$ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363
Would give something like:
commit f31a441398fb7834fde24c5b0c2974182a431363
Author: xx <xx@xx.nl>
Date: Tue Sep 29 17:23:22 2015 +0200
added fb skd and XLForm
:000000 100644 0000000... 90a20d7... A Pods/Bolts/Bolts/Common/BFCancellationToken.h
:000000 100644 0000000... b5006d0... A Pods/Bolts/Bolts/Common/BFCancellationToken.m
:000000 100644 0000000... 3e7b711... A Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
:000000 100644 0000000... 9c8a7ae... A Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
:000000 100644 0000000... bd6e7a1... A Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
:000000 100644 0000000... 947f725... A Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
:000000 100644 0000000... cf7dcdf... A Pods/Bolts/Bolts/Common/BFDefines.h
:000000 100644 0000000... 02af9ba... A Pods/Bolts/Bolts/Common/BFExecutor.h
:000000 100644 0000000... 292e27c... A Pods/Bolts/Bolts/Common/BFExecutor.m
:000000 100644 0000000... 827071d... A Pods/Bolts/Bolts/Common/BFTask.h
...
I know this answer doesn't really match "with no extraneous information.", but I still think this list is more useful then just the filenames.
There is a simple trick to view as a file listing, just add :
after the hash.
git show 9d3a52c474:
You can then drill in,
git show 9d3a52c474:someDir/someOtherDir
If you hit a file you'll get the raw version of the file; which sometimes is what you want if you're only looking for a nice reference or key pieces of code (diffs can make everything a mess),
git show 9d3a52c474:someDir/someOtherDir/somefile
Only drawback of this method is that it doesn't easily show a tree of files.
Preferred Way (because it's a plumbing command; meant to be programmatic):
$ git diff-tree --no-commit-id --name-only -r bd61ad98
index.html
javascript/application.js
javascript/ie6.js
Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)
$ git show --pretty="" --name-only bd61ad98
index.html
javascript/application.js
javascript/ie6.js
--no-commit-id
suppresses the commit ID output.--pretty
argument specifies an empty format string to avoid the cruft at the beginning.--name-only
argument shows only the file names that were affected (Thanks Hank). Use --name-status
instead, if you want to see what happened to each file (Deleted, Modified, Added)-r
argument is to recurse into sub-treesIf you are using oh-my-zsh and git plugin, the glg shortcut is helpful.
I like this:
git diff --name-status <SHA1> <SHA1>^
List all files in a commit tree:
git ls-tree --name-only --full-tree a21e610