I'm using git within a perforce repository. I want to be able to know exactly what files were affected by a git commit so I can turn around with a post-commit hook and open those files for edit in perforce, so the perforce server knows about the changes.
Is there a way I can get a list, within the post-commit hook, of exactly what files were affected by the commit?
views:
103answers:
2Doesn't look like that gets me a list of the actual files - it's showing me the affected directories.
bergyman
2010-01-27 18:13:31
...nevermind, digging through the options of diff-tree this may work.
bergyman
2010-01-27 18:18:09
+1
A:
Get the affected paths (relative to $GIT_DIR
) of the current branch's head with
git show --pretty=oneline --name-only HEAD | sed 1d
Greg Bacon
2010-01-27 18:56:05
You can get the exact same output with:git diff-tree --name-only -r HEAD | sed 1d Interesting that there's a few ways to do this...
bergyman
2010-01-27 19:10:44
In this case, go with `git diff-tree` over `git show` because the former is low-level plumbing, as opposed to porcelain meant for human use. See http://progit.org/book/ch9-1.html
Greg Bacon
2010-01-27 19:16:25