git - 拒绝 git commit 并显示与上次提交相同的消息?

标签 git

所以,我偶尔会犯错误,按向上键的次数太多或太少,最终会执行 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/

相关文章:

bash - git !alias 可以在 bash 和 Powershell 中使用

eclipse : "re-indexing repository workspace"或 "Computing Git status for repository workspace"

git - 是否可以在 gitlab-ci 中将另一个分支构建到另一个目录?

git - 使用 EGit merge 会导致 merge 完成的所有更改的提交

git - 避免在执行 git push 时 pop 询问用户名的 pop 窗口

git - 如何在 git 标记消息中包含换行符

java - Eclipse 崩溃,现在未生成 R 文件

git - 如何在 git push 后运行 bash 脚本

git - hg 中的工作流程如何进行非常频繁的提交?

svn - 将 git-svn 与现有的 svn 项目一起使用