为了将标记为“squash”的提交压缩到前面的提交中,您应该可以将单词“pick”更改为“squash”。
Git Documentation: Rewriting History
一个例子:
$ git log --oneline
acb05b3 Some final commit.
4968dbd Fixing an error in commit df89a81.
df89a81 Something committed too early.
c365eab Another commit...
625889f A commit...
70f29fd The beginning.
我想之前的最近一次衍合到3个提交:
$ git rebase -i HEAD~3
这给在文本编辑器下面的文字:
pick df89a81 Something committed too early.
pick 4968dbd Fixing an error in commit df89a81.
pick acb05b3 Some final commit.
# Rebase c365eab..acb05b3 onto c365eab (3 command(s))
其中我改成这样:
pick df89a81 Something committed too early.
squash 4968dbd Fixing an error in commit df89a81.
pick acb05b3 Some final commit.
# Rebase c365eab..acb05b3 onto c365eab (3 command(s))
一旦退出,然后我得到一个包含其他编辑器这样的:
# This is a combination of 2 commits.
# The first commit's message is:
Something committed too early.
# This is the 2nd commit message:
Fixing an error in commit df89a81.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
对此我改成这样:
# This is a combination of 2 commits.
# The first commit's message is:
This is the squashed commit. It and everything after it get new commit hashes.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
现在如果我期待在我的新历史记录中:
$ git log --oneline
8792fef Some final commit.
df775c4 This is the squashed commit. It and everything after it get new commit hashes.
c365eab Another commit...
625889f A commit...
70f29fd The beginning.
图像链接已损坏。 –
那是因为我改变了它,再试一次 – PositiveGuy