因此,我偶尔会犯一次太多或太少的错误,最终会做git commit -am "changed foo"
而不是./foo_test
,导致我的回购额外提交,然后我必须处理。是否有可能让git拒绝任何提交的消息匹配以前提交的提交的消息?拒绝与之前提交的消息相同的消息提交git commit?
2
A
回答
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
相关问题
- 1. git提交模板消息
- 2. 如何引用git commit提交消息中的前一个提交
- 3. Git:如何编辑之前不是最新提交的提交的消息?
- 4. SVN提交与消息
- 5. 在git中提交消息前缀
- 6. Git提交一个提交消息,没有别的?
- 7. svn提交消息
- 8. Launchpad提交消息
- 9. 如何跳过“git commit --amend”中的提交消息步骤?
- 10. 在Windows上的git commit-msg中访问提交消息
- 11. 在提交Git之前检查消息的代码注释
- 12. VSCode中的多行git提交消息
- 13. 如何通过提交消息找到git提交仓库?
- 14. 意外推送提交:更改git提交消息
- 15. 为什么git提示我提交后合并提交消息?
- 16. 在git中输出给定提交的提交消息
- 17. 如何编辑推送Git提交的提交消息
- 18. 在git中修改过去提交的提交消息
- 19. GIT中从主合并提交消息
- 20. git突出显示提交消息
- 21. git:中止提交输入消息
- 22. Git:合并冲突并提交消息
- 23. Git撤消 - 确保本地文件与之前提交的Git相同
- 24. 如何与消息提交从文件
- 25. git commit error:无效提交信息
- 26. vimrc自动提交w /消息提示
- 27. Git(assembla) - 提交提交消息中引用前一个变更集的语法
- 28. git cherry:如何通过提交消息识别等价提交
- 29. 从提交消息获取Git提交散列
- 30. git:如何取消注释默认提交消息文本?
正如一个侧面说明:'git的承诺-a'不被认为是一个很好的做法反正。建议每次检查你要提交的内容,所以常用的工作流程是'git status',然后'git add'或'git add -a',然后'git commit'。 –
penartur
2012-04-18 06:54:11
你可以设置一个预先提交的钩子,la http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes虽然在这种情况下它可能只是正如所暗示的那样,更容易撤消它。 – ngm 2012-04-18 06:59:48