2012-04-18 170 views
2

因此,我偶尔会犯一次太多或太少的错误,最终会做git commit -am "changed foo"而不是./foo_test,导致我的回购额外提交,然后我必须处理。是否有可能让git拒绝任何提交的消息匹配以前提交的提交的消息?拒绝与之前提交的消息相同的消息提交git commit?

+2

正如一个侧面说明:'git的承诺-a'不被认为是一个很好的做法反正。建议每次检查你要提交的内容,所以常用的工作流程是'git status',然后'git add '或'git add -a',然后'git commit'。 – penartur 2012-04-18 06:54:11

+0

你可以设置一个预先提交的钩子,la http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes虽然在这种情况下它可能只是正如所暗示的那样,更容易撤消它。 – ngm 2012-04-18 06:59:48

回答

6

与其完全拒绝它,为什么不直接撤消它呢?

# Leaves all changes as 'changes to be committed', but 
# uncommits the most recent commit 
git reset --soft HEAD~ 
# Leaves all changes as changed working copy files (ie, 
# unstages them as well) 
git reset HEAD~ 
# Lets you edit the most recent commit message 
git commit --amend 
# Lets you do bulk surgery on your revision history, deleting 
# or merging dozens of commits in one operation 
git rebase -i <last good commit, eg origin/mainline> 

如果你真的希望这是断然拒绝,检查出.git/hooks/prepare-commit-msg - 你可以添加脚本那里得到最新提交的信息(通过git cat-file commit HEAD),并把它比作传入的提交信息。如果它们匹配,exit 1放弃提交。

0

使用post-commit钩子脚本来检查。

如果相同,则git的复位--mixed HEAD〜1