How can I print a plain list of all files that were part of a given commit?
Although the following lists the files, it also includes unwanted diff information for each:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
How can I print a plain list of all files that were part of a given commit?
Although the following lists the files, it also includes unwanted diff information for each:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
Preferred Way (because it's a plumbing command; meant to be programmatic):
$ git diff-tree --no-commit-id --name-only bd61ad98 -r
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-treesgit rm --cached <file>
. This makes commit only a technical term in this case and showing a bunch of files (as part of the commit) is totally misleading because Git does not show whether a file were added or removed. –
Sterilant Merge branch '<branch>' of bitbucket.org:xxx/xxx into master
–
Numberless diff-tree
won't work when looking at the root commit. –
Spenserian --name-only
option with --name-status
will give more clear summary. –
Morisco git log --name-only -n 1 <hash>
The last commit would be: git log --name-only -n 1 HEAD~1..HEAD
–
Air man git-diff-tree
. –
Dichotomy git show --name-only <COMMIT_ID>
? –
Wadmal git show
is "porcelain" (meant to be user facing) and git diff-tree
is "plumbing" (meant to be used programmatically, e.g. from scripts). The interface for the former may change over time (so the git maintainers could drop --name-only
although I don't imagine they would) for useability reasons, whereas the interface for the latter will be kept as stable as possible for compatibility reasons. –
Np --pretty=""
will also work for most things and is easier to remember, e.g. vi $(git show --pretty="" --name-only)
–
Delcine bd61ad98
? –
Grussing HEAD~1..HEAD
as HEAD is the default. Also you need to use --pretty=""
to remove all the log cruft. The command should be: git log --pretty="" --name-only -n 1
–
Overthrust HEAD
. –
Luckless git log | grep commit | awk '{print $2}' | xargs -n 1 git diff-tree ... | sort | uniq
–
Reform git diff --name-only 8dd6615f24 880ba9a
–
Brazee -m
flag: git diff-tree --no-commit-id --name-only -m -r bd61ad98
. That may provide non-unique lines - it lists files from each merge head separately from the other merge heads. On UNIX-like platforms, you can tack |sort|uniq
on the end if that's an issue. –
Pellet git show --stat (hash)
as suggested in this answer from @VaTo outputs a bit more than you asked for but is easy to remember and perfectly fine in case you are a human and not a machine. Maybe worth mentioning here in the accepted answer to provide an easy to type alternative. –
Spiritualize --pretty=""
. Why is that? –
Pontifex git rev-parse --short HEAD
you will get changed files for your current commit:git diff-tree --no-commit-id --name-status -r `git rev-parse --short HEAD`
–
Ducks HEAD
to git diff-tree
directly? Why git rev-parse
should be used? –
Bernstein diff-tree
outputs renames as both the old and new name. show
only outputs the new name. Use diff-tree --find-renames
for the similar behavior –
Bacteriology git log | grep commit | awk '{print $2}' | xargs git show --pretty="" --name-only
–
Distasteful If you want to get the list of changed files:
git diff-tree --no-commit-id --name-only -r <commit-ish>
If you want to get the list of all files in a commit, you can use
git ls-tree --name-only -r <commit-ish>
git ls-tree --name-only HEAD
(the <commit-ish> parameter is required; in this example it is HEAD) works for me with git version 1.6.4.3 –
Parietal --no-commit-id
to avoid printing the SHA1, like so: git diff-tree --no-commit-id --name-only -r <commit-ish>
–
Zsa -r
/ -t
option, did you? Because diff-tree handles both modified and added files. If you want to list all new (added) files, use git diff-tree -r --name-only --no-commit-id --diff-filter=A <commit-ish>
–
Parietal -r
option is present. I realized that I supplied the wrong commit hash, and diff-tree
appears to work on the correct commit. But still, it's strange that it doesn't return anything for a certain commit, which clearly contains a change to a file: pastebin.com/ED0pHtf5 -diff-filter
works like a charm - many thanks! –
Platas git diff d730c6
shows difference between commit and your working area; use git diff d730c6^!
or git show d730c6
instead –
Parietal git log --pretty="" --name-only
for me! –
Cling git ls-tree --name-only -r
shows more complete list of files for merge commit - it shows not only the files that were modified during merge commit, but actually all the files brought to repo from 2 branches that made that merge commit. –
Succinate I'll just assume that gitk
is not desired for this. In that case, try git show --name-only <sha>
.
gitk
is actually a decent way of reviewing the files and displaying the file that the diff is on. e.g. Code reviewing a monster commit from a peer. –
Glorify I personally use the combination of --stat and --oneline with the show command:
git show --stat --oneline HEAD
git show --stat --oneline b24f5fb
git show --stat --oneline HEAD^^..HEAD
If you do not like/want the addition/removal stats, you can replace --stat with --name-only
git show --name-only --oneline HEAD
git show --name-only --oneline b24f5fb
git show --name-only --oneline HEAD^^..HEAD
alias gits='git show --stat --oneline'
, then gits
by itself shows the latest changes (in HEAD), while gits b24f5fb
can be used to show any revision's changes. –
Brail git config --global alias.changes 'show --stat --oneline'
. Then you can type git changes
(with an optional commit-ish) and get the output from the first examples above. –
Cimbalom git config --global alias.changes "show --stat --oneline"
–
Kaiulani git show
also works for reviewing stashed changes: e.g. git show --stat --oneline stash@{1}
–
Brachial You can also do
git log --name-only
and you can browse through various commits, commit messages and the changed files.
Type q to get your prompt back.
git show 5944ad2a8b5 --name-only
to list the name of a specific commit –
Cantankerous --name-only
out? Or in other words, what is it supposed to do and how does it answer the question? –
Tawanda Recently I needed to list all changed files between two commits. So I used this (also *nix specific) command
git show --pretty="format:" --name-only START_COMMIT..END_COMMIT | sort | uniq
Or as Ethan points out:
git diff --name-only START_COMMIT..END_COMMIT
Using --name-status
will also include the change (added, modified, deleted, etc.) next to each file:
git diff --name-status START_COMMIT..END_COMMIT
git diff --name-status START_COMMIT..END_COMMIT
then you don't need the trailing |sort | uniq
. –
Sheila git diff --name-only START_COMMIT..END_COMMIT
–
Sheila git diff --name-only START_COMMIT..END_COMMIT | grep -v -e '**.png' -e '**.xml'
. I wanted a list of code changes only for a huge PR that had added thousands of PNGs and XML layouts. –
Orator Simplest form:
git show --stat (hash)
That's easier to remember and it will give you all the information you need.
If you really want only the names of the files you could add the --name-only
option.
git show --stat --name-only (hash)
I use the changed alias quite often. To set it up:
git config --global alias.changed 'show --pretty="format:" --name-only'
Then:
git changed (lists files modified in last commit)
git changed bAda55 (lists files modified in this commit)
git changed bAda55..ff0021 (lists files modified between those commits)
Similar commands that may be useful:
git log --name-status --oneline (very similar, but shows what actually happened M/C/D)
git show --name-only
Use
git log --name-status
This will show you the commit id, message, the files changed and whether it was modified, created, added, or deleted. Somewhat of an all-in-one command.
Try this command for name and changes number of lines
git show --stat <commit-hash>
Only show file names
git show --stat --name-only <commit-hash>
For getting the last commit hash, try this command:
git log -1
Last commit with show files name and file status modify, create, or delete:
git log -1 --oneline --name-status <commit-hash>
Or for all
git log
For more advanced git log information, read these articles:
git log
doesn't give you the filenames... –
Tayib Using the standard git diff
command (also good for scripting):
git diff --name-only <sha>^ <sha>
If you also want the status of the changed files:
git diff --name-status <sha>^ <sha>
This works well with merge commits.
To list the files changed on a particular commit:
git show --pretty=%gd --stat <commit_id>
To list the files changed on recent commit:
git show --pretty=%gd --stat
$ git log 88ee8^..88ee8 --name-only --pretty="format:"
git show --name-only a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
OK, there are a couple of ways to show all files in a particular commit...
To reduce the information and show only names of the files which committed, you simply can add --name-only
or --name-status
flag... These flags just show you the file names which are different from previous commits as you want...
So you can do git diff
followed by --name-only
, with two commit hashes after <sha0> <sha1>
. Something like below:
git diff --name-only 5f12f15 kag9f02
I also created the below image to show all steps to go through in these situations:
Use a simple one-line command, if you just want the list of files changed in the last commit:
git diff HEAD~1 --name-only
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 they were added(A
), deleted(D
), or modified(M
);
$ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363
Would give something like:
commit f31a441398fb7834fde24c5b0c2974182a431363
Author: xx <[email protected]>
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 than just the filenames.
whatchanged
instead of supplying parameters. –
Eyespot I use this to get the list of changed files in a merge commit
λ git log -m -1 --name-only --pretty="format:"
configs/anotherconfig.xml
configs/configsInRepo.xml
or
λ git log -m -1 --name-status --pretty="format:"
A configs/anotherconfig.xml
M configs/configsInRepo.xml
I use this to get the list of modified files between two changesets:
git diff --name-status <SHA1> <SHA2> | cut -f2
git diff --name-status .. | grep ^[^D] | cut -f2
–
Franciscafranciscan I found a perfect answer to this:
git show --name-status --oneline <commit-hash>
So that I can know
which files were just modified (M)
Which files were newly added (A)
Which files were deleted (D)
I like this:
git diff --name-status <SHA1> <SHA1>^
A
& D
(add and delete) file statuses backwards, because it's showing the diff from the specified commit to the previous commit, instead of the other way around. It should be git diff --name-status <SHA1>^ <SHA1>
. –
Pindling Display the log.
COMMIT
can be blank (""), the SHA-1 hash, or a shortened version of the SHA-1 hash.
git log COMMIT -1 --name-only
This will list just the files and is very useful for further processing.
git log COMMIT -1 --name-only --pretty=format:"" | grep "[^\s]"
List the files that changed in a commit:
git diff --name-only SHA1^ SHA1
This doesn't show log messages, extra newlines, or any other clutter. This works for any commit, not just the current one.
git diff SHA1^ SHA1
and git show SHA1
. –
Ascender git show
also shows the commit message –
Paduasoy Perhaps I missed it did anyone mention if you want to augment the log x previous commits using the 'log' command to include the names of the files effected then add --name-only on the end.
so:
git log -n3
to see the last comments of the last 3 commits.
git log -n3 --name-only
to see the comments and files effected in the last 3 commits.
Only the file list (not even commit message):
git show --name-only --pretty=format:
E.g. open all changed files in your editor:
git show --name-only --pretty=format: | xargs "$EDITOR"
git show
. –
Molybdenous A combination of git show --stat
and a couple of sed commands should trim the data down for you:
git show --stat <SHA1> | sed -n "/ [\w]\*|/p" | sed "s/|.\*$//"
That will produce just the list of modified files.
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
The only drawback of this method is that it doesn't easily show a tree of files.
If your commit happens to be at the initial HEAD
position
git show HEAD@{0}
this should work fine.
List all files in a commit tree:
git ls-tree --name-only --full-tree a21e610
© 2022 - 2024 — McMap. All rights reserved.
git log --until 2013-05-21 --pretty="short" --name-only
with a good effect. – Illiquidn
commits tillmaster
:git diff-tree --name-status -r @{3} master
– Sewellyngit diff --name-only master
- To list ALL changed files on current branch, comparing to master branch. – Arterial