所以,我偶尔会犯错误,按向上键的次数太多或太少,最终会执行 git commit -am "changed foo"
而不是 ./foo_test
,导致在我的 repo 中有额外的提交,然后我必须处理。是否可以让 git 拒绝任何其消息与先前提交的提交消息匹配的提交?
最佳答案
与其直接拒绝它,不如撤消它?
# 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
以中止提交。
关于git - 拒绝 git commit 并显示与上次提交相同的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10204264/