开发者

Is there a way to get the affected files of a commit with a git post-commit hook?

开发者 https://www.devze.com 2022-12-18 10:46 出处:网络
I\'m using git within a perforce repository. I want to be able to know exactl开发者_开发问答y what files were affected by a git commit so I can turn around with a post-commit hook and open those files

I'm using git within a perforce repository. I want to be able to know exactl开发者_开发问答y 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?


Get the affected paths (relative to $GIT_DIR) of the current branch's head with

git show --pretty=oneline --name-only HEAD | sed 1d


To get the raw data:

git diff-tree HEAD


is git log --name-only what you're looking for? git log --name-status also shows the action like M for modified, A for added (i presume) etc.

Lastly, the option --pretty=oneline might be handy for easier parsing.

Obviously you've probably figured this out already but I added this for future reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号