tags:

views:

5691

answers:

9

I need to write a script that retrieves all files that were committed for a given SHA1. I have difficulty getting a nice formatted list of all files that were part of the commit.

I have tried: git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d

Although listing the files it also includes additional diff information that I don't need. I am hoping there is a simple git command that will provide such a list without me having to parse it from the above command.

+6  A: 

I'll just assume that gitk is not desired for this. In that case, try git show --name-only <sha>.

Hank Gay
Thanks Hank. Ryan managed to use your example and got it to work I needed.
Philip Fourie
+30  A: 

This should get you a little closer to your goal.

$ git show --pretty="format:" --name-only bd61ad98

index.html
javascript/application.js
javascript/ie6.js

The --pretty argument specifies an empty format string to avoid the cruft at the beginning. The --name-only argument shows only the file names that were affected (Thanks Hank).

Ryan McGeary
Thank that works perfectly.
Philip Fourie
A: 

A combination of "git show --stat" (thanks Ryan) 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.

seanhodges
+6  A: 
$ git log 88ee8^..88ee8 --name-only --pretty="format:"
Pat Notz
+3  A: 

If you want to get list of changed files:

git diff-tree --name-only -r <commit-ish>

You would get SHA1 of on first line, though.

If you want to get list of all files in a commit, you can use

git ls-tree --name-only -r <commit-ish>
Jakub Narębski
The ls-tree with --name-only does not seem to work on 1.6.4.4 or 1.6.3.3. Do you think this is a bug ?
krosenvold
`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
Jakub Narębski
It turns out the ordering of the parameters is significant here. The one in your post does not work, while the one in your response *does* work - at least until you update your post ;)
krosenvold
Thanks @krosenvold, I updated my post... Some git commands are not rewritten using parseopt, so ordering of options and non-option agruments might be significant.
Jakub Narębski
+2  A: 

I like this:

git diff --name-status <SHA1> <SHA1>^
skiphoppy
+1  A: 

I use this to get list of modified files between two changesets:

git diff --name-status <SHA1> <SHA2> | cut -f2
A: 

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

Hope this helps someone... don't badge me with "Necromancer" though :)

lunohodov