有几种方法可以更改之后提交的提交的消息:
git commit --amend # for the most recent commit
git rebase --interactive master~2 # but requires *parent*
如何更改没有父提交记录的第一个提交记录的提交信息?
有几种方法可以更改之后提交的提交的消息:
git commit --amend # for the most recent commit
git rebase --interactive master~2 # but requires *parent*
如何更改没有父提交记录的第一个提交记录的提交信息?
git
命令完全匹配,即:git rebase --interactive --autosquash --autostash --root
。 - pvandenberk假设你的工作目录是干净的,你可以执行以下操作。
# 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
git rebase --onto HEAD <sha1-of-root> master
命令。 - Andrewgit rebase
的<upstream>的_原始_根提交记录。 git rebase
应用<分支>(master
)中不在<upstream>的提交记录; HEAD
不在master
中,所以你的版本尝试应用所有master
的提交记录。 - Andrewgit rebase --onto HEAD <sha1-of-root> master
,其中 <sha1-of-root>
与 git checkout <sha1-of-root>
中使用的相同。否则,您将会有两个“first commit”。 - Andy--root
选项出现之前给出的。 - CB Bailey在ecdpalma的回答的基础上,现在你可以使用--root
选项告诉rebase
你想要重写根/第一个提交:
git rebase --interactive --root
然后根提交将会在重新基于的TODO列表中显示,您可以选择编辑或者改写:
reword <root commit sha> <original message>
pick <other commit sha> <message>
...
--root
的解释(强调是我的):<branch>
到达的提交,而不是将它们限制在一个<upstream>
中。这使您可以在分支上重新定义根提交(或根提交)。仅提供一个与评分较高答案不同的选择:
如果您正在创建一个存储库,并且事先知道将来会在其“第一个”真正提交的顶部进行变基,那么您可以在开头进行明确的空提交以完全避免此问题:
git commit --allow-empty -m "Initial commit"
只有在那之后才开始进行“真正”的提交。然后你可以按照标准的方式在该提交之上进行简单的变基,例如 git rebase -i HEAD^
。
.gitattributes
文件,而不是进行空提交。 - jakub.gcd test
git init
touch initial
git add -A
git commit -m "Initial commit"
touch a
git add -A
git commit -m "a"
touch b
git add -A
git commit -m "b"
git log
-->
8e6b49e... b
945e92a... a
72fc158... Initial commit
git filter-branch --msg-filter \
"sed \"s|^Initial commit|New initial commit|g\"" -- --all
git log
-->
c5988ea... b
e0331fd... a
51995f1... New initial commit
-- --all
选项确实是在这种情况下处理根提交的关键。 - sschuberth