In a git post-commit hook how do I get a list of the files that were changed?

一世执手 提交于 2019-12-03 13:03:12

When writing scripts around git, you should try to stick to the plumbing commands — their format is less likely to change and easier to parse. Here is a command which outputs the names of the paths which changed in a commit:

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

That aside, you may wish to examine the index, as it contains timestamps about when the files were staged, which might give you an extra edge; however, I don’t believe there is a way to access this information.

Been doing some research and found that git log --name-only -n1 is the best approach. It's not difficult to get the min. and max. timestamps out of the files by doing a bit of string matching and using the Python os.stat module.

As a general solution it still isn't great because the modification times on the files doesn't really reflect the reality of the time spent actually.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!