简体   繁体   English

检查是否针对新的GIT存储库进行了更改

[英]check if changes are staged for a new GIT repository

I need to detect if there are any changes staged to commit for a new GIT repository via a shell script. 我需要检测是否有任何更改通过外壳程序脚本提交给新的GIT存储库。

git diff --cached HEAD

Above command returns 0 when changes are staged, but requires a HEAD . 暂存更改后,以上命令将返回0 ,但需要HEAD If it cannot find one, it returns 128 (in case of new repository). 如果找不到一个,则返回128 (如果是新存储库)。

So How to detect if there were changes staged for a new repo and whether I need to commit? 那么,如何检测是否有针对新仓库的变更以及我是否需要提交?

If I try to commit when there are no changes to commit, it exits with return code 1 . 如果我尝试commit时,有没有改变承诺,它与返回码退出1

I am not sure if I can use this fact. 我不确定是否可以使用这个事实。

Does commit return 1 IF AND ONLY IF there are no changes to commit? 如果没有要提交的更改,提交是否返回1

I couldn't find any documentation supporting this. 我找不到任何支持此操作的文档。

Note: I am not trying to auto-commit when a file is changed, I am aware I can use inotifywait for that. 注意:更改文件时,我不会尝试自动提交,我知道我可以inotifywait使用inotifywait

As of git 1.7.4.1, just 从git 1.7.4.1开始,

git diff --cached --quiet

should do it. 应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM