我正在尝试编写一个执行git commit的fabric脚本;但是,如果没有什么可提交的,则git退出时状态为1。部署脚本将其视为不成功,并退出。我确实想检测到实际的失败-提交,所以我不能只是给布匹一个毛毯忽略git commit的失败。我如何让空提交失败被忽略,这样部署就可以继续,但仍然捕获当真正提交失败时引起的错误?
def commit():
local("git add -p && git commit")发布于 2011-11-14 15:27:20
事先通过检查git的退出代码来捕获此条件?
例如(在shell中):
git add -A
git diff-index --quiet HEAD || git commit -m 'bla'编辑:根据霍格的评论,修正了git diff命令。
发布于 2011-11-14 15:16:13
来自git commit手册页:
--allow-empty
Usually recording a commit that has the exact same tree as its
sole parent commit is a mistake, and the command prevents you
from making such a commit. This option bypassesthe safety, and
is primarily for use by foreign SCM interface scripts.发布于 2021-07-22 05:53:10
只是用一个显式的Tobi & Holger语句扩展了if的答案。
git add -A
if ! git diff-index --quiet HEAD; then
git commit -m "Message here"
git push origin main
fi让我们稍微解释一下。
git add -A:分阶段进行更改(下一步所需)git diff-index --quiet HEAD将比较您的阶段性更改和头部。
--quiet是重要的,因为它将暗示--exit-code,“如果存在差异,则使用代码1使程序退出,而0表示没有差异”。见-安静。
https://stackoverflow.com/questions/8123674
复制相似问题