如何在没有错误的情况下提交任何内容? [英] How to git commit nothing without an error?

查看:115
本文介绍了如何在没有错误的情况下提交任何内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个结构脚本来执行 git commit ;但是,如果没有提交的内容,git将以 1 的状态退出。部署脚本将其视为不成功并退出。我确实希望检测到 提交失败的情况,所以我不能只为 git commit 失败提供结构忽略。我怎样才能允许空承诺失败被忽略,以便部署可以继续,但仍然捕获真正的提交失败时导致的错误?

  def commit():
local(git add -p&&git commit)


  git add -A 
git diff-index --quiet HEAD || git commit -m'bla'

编辑:修正了 git diff根据Holger的评论,命令


I'm trying to write a fabric script that does a git commit; however, if there is nothing to commit, git exits with a status of 1. The deploy script takes that as unsuccessful, and quits. I do want to detect actual failures-to-commit, so I can't just give fabric a blanket ignore for git commit failures. How can I allow empty-commit failures to be ignored so that deploy can continue, but still catch errors caused when a real commit fails?

def commit():
    local("git add -p && git commit")

解决方案

Catch this condition beforehand by checking the exit code of git diff?

For example (in shell):

git add -A
git diff-index --quiet HEAD || git commit -m 'bla'

EDIT: Fixed git diff command according to Holger's comment.

这篇关于如何在没有错误的情况下提交任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆