拒绝使用与上一次提交相同的消息的git提交?

Pau*_*cks 2 git

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

bdo*_*lan 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>
Run Code Online (Sandbox Code Playgroud)

如果你真的想要彻底拒绝这一点,请查看.git/hooks/prepare-commit-msg- 你可以在那里添加一个脚本来获取最新的提交消息(via git cat-file commit HEAD)并将其与传入的提交消息进行比较.如果它们匹配,则exit 1中止提交.