因此,我偶尔会犯一次太多或太少的错误,最终会做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:如何编辑之前不是最新提交的提交的消息?
- 3. 在git中提交消息前缀
- 4. svn提交消息
- 5. Launchpad提交消息
- 6. 如何跳过“git commit --amend”中的提交消息步骤?
- 7. 在提交Git之前检查消息的代码注释
- 8. 意外推送提交:更改git提交消息
- 9. 为什么git提示我提交后合并提交消息?
- 10. 在git中输出给定提交的提交消息
- 11. Git:合并冲突并提交消息
- 12. git:中止提交输入消息
- 13. Git撤消 - 确保本地文件与之前提交的Git相同
- 14. git cherry:如何通过提交消息识别等价提交
- 15. 从提交消息获取Git提交散列
- 16. git:如何取消注释默认提交消息文本?
- 17. Github提交消息链接
- 18. System.InvalidOperationException:当提交消息
- 19. Github提交消息标记
- 20. 正确提交消息
- 21. 参考消息提交
- 22. GitHub提交消息中的图形
- 23. 使用git filter-branch重写作者/提交者并同时提交消息
- 24. 修改推送提交的提交消息。 (Mercurial)
- 25. Git推送所有提交作为单个提交与自定义消息
- 26. SVN提交失败,错误消息
- 27. 提交后显示警告消息
- 28. 关闭提交消息中的git路径解析
- 29. Mercurial是否支持空提交消息?
- 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