2017-05-25 237 views
1

我是一个新兴的rebasing,并且绝对没有压扁之前的提交。如何用git rebase压扁-i

虽然签出到我的本地分支称为'无论',然后我做了一个git add和git commit,然后rebase。

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

git rebase -i development 

发展是我们的,我们变基之上我们提交主线分支。当我这样做,我的命令得到: enter image description here

我需要向下滚动到甚至可以看到最新的承诺,我只是试图变基上开发分支的顶部:enter image description here

我不知道该怎么在这一点上做。在这一点上,我显然已经做出了我的改变,然后做了一次重做,所以有一个命令来压扁,我压扁了什么?我不想压缩开发分支的整个历史吗?或者你在之前压扁了你做的?我迷失了一下。

+0

图像链接已损坏。 –

+1

那是因为我改变了它,再试一次 – PositiveGuy

回答

0

为了将标记为“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. 
+0

奇怪的是我看不到列表中的所有选择,有没有办法向上滚动? – PositiveGuy

+0

哪些提交丢失,您当前的分支是什么,当前分支与分支'development'有什么不同? 'git rebase -i development'应该尝试改变当前分支中不属于分支'development'的每个提交。 –

+0

所以我检查出'mybranch'。我做了一对夫妇。和git提交。所以我的本地分支有几个提交。然后我在开发分支(不是我的分支)上做了一个rebase。所以,当我rebase我看到开发分支在该图片的历史 – PositiveGuy