How to discover a file is changed in GIT during a push

£可爱£侵袭症+ 提交于 2019-12-11 02:13:04

问题


when I push something to my GIT repository, the post-receive hook is triggered and executes some scripts. Is it possible doing something before the execution these scripts if (and only if) a specific file is changed respect to the previous push (for example .sql file)?

Thanks

Randomize


回答1:


In the same post-receive hook as a first step or in a pre-receive or update hook, you can use

git diff-tree --name-status -rz

and pass in the new and old ref that are passed in to the hook ( either stdin or arguments) and get the files, check for modified - M - status in the output and do what you need.

Also see here for alternate ways: http://progit.org/book/ch7-4.html



来源:https://stackoverflow.com/questions/8200522/how-to-discover-a-file-is-changed-in-git-during-a-push

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