13r*_*ren 307 git git-rebase git-amend git-commit git-rewrite-history
有办法从以后的提交中更改消息:
git commit --amend # for the most recent commit
git rebase --interactive master~2 # but requires *parent*
Run Code Online (Sandbox Code Playgroud)
如何更改第一次提交(没有父级)的提交消息?
ecd*_*lma 527
从Git 1.7.12开始,您现在可以使用
git rebase -i --root
Run Code Online (Sandbox Code Playgroud)
CB *_*ley 263
假设您有一个干净的工作树,您可以执行以下操作.
# checkout the root commit
git checkout <sha1-of-root>
# amend the commit
git commit --amend
# rebase all the other commits in master onto the amended root
git rebase --onto HEAD HEAD master
Run Code Online (Sandbox Code Playgroud)
小智 63
要扩展ecdpalma的答案,您现在可以使用该--root
选项告诉rebase
您要重写root/first commit:
git rebase --interactive --root
Run Code Online (Sandbox Code Playgroud)
然后根提交将显示在rebase TODO列表中,您可以选择编辑或重新编写它:
reword <root commit sha> <original message>
pick <other commit sha> <message>
...
Run Code Online (Sandbox Code Playgroud)
这是--root
来自Git rebase文档(强调我的)的解释:
重新引用可以访问的所有提交
<branch>
,而不是使用<upstream>
.这允许您在树枝上重新定义根提交.
jak*_*b.g 12
只是提供更高评级答案的替代方案:
如果你正在创建一个repo,并且知道你将来会在其"第一次"实际提交之上进行变基,你可以通过在开头做一个明确的空提交来完全避免这个问题:
git commit --allow-empty -m "Initial commit"
Run Code Online (Sandbox Code Playgroud)
然后才开始做"真正的"提交.然后,您可以轻松地在标准方式的基础上进行重新设置,例如git rebase -i HEAD^
归档时间: |
|
查看次数: |
36472 次 |
最近记录: |