繁体   English   中英

如何使用 git rebase -i 进行压缩

[英]How to squash with git rebase -i

我对变基有点陌生,以前绝对没有压缩过提交。

在签出到名为“whatever”的本地分支时,我执行 git add 和 git commit,然后重新设置基准。

我想这是变基的正确方法或至少一种方法:

git rebase -i development

development 是我们的主线分支,我们在此基础上重新提交我们的提交。 当我执行该命令时,我得到: 在此处输入图像描述

我必须向下滚动才能查看我刚刚尝试在开发分支之上重新构建的最新提交: 在此处输入图像描述

我现在不知道该怎么做。 我显然已经提交了我的更改,然后做了一个变基。 有没有要挤压的命令,我要挤压什么? 我不想压缩开发分支的整个历史。 壁球是你在变基之前做的事情吗? 我有点迷路了。

您应该能够将单词“pick”更改为“squash”,以便将标记为“squash”的提交压缩到前面的提交中。

Git 文档:重写历史

一个例子:

$ 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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM