简体   繁体   English

创建新分支后,Git变基(压扁)

[英]Git rebasing (squash) after creating new branch

Suppose I have Commit history as follows: 假设我的提交历史如下:

a -- b -- c                  <-- Branch1
           \
            d -- e           <-- Branch2

Now I checkout to branch1 and squash commits b and c into x. 现在我签出到branch1,并将bc提交到x中。

I expected something like this to happen. 我期望这样的事情会发生。

a -- x                  <-- Branch1
      \
       d -- e           <-- Branch2

But on running git log on Branch1, it shows: 但是在Branch1上运行git log时,它显示:

a -- x

and on running git log on Branch2, it shows: 在Branch2上运行git log时,它显示:

a -- b -- c -- d -- e

now even if I checkout to branch2 and squash b , c , it won't generate x but some other commit hash. 现在,即使我签出到branch2并压扁bc ,它也不会生成x而是其他一些提交哈希。

So my question is, How do I squash those 2 commits properly such that it is reflected in all branches? 所以我的问题是,如何正确压缩这2个提交,使其反映在所有分支中?

Also how do I fix up once I already did that? 另外,一旦完成该如何解决?

Now I checkout to branch1 and squash commits b and c into x. 现在我签出到branch1,并将b和c提交到x中。

after that you still are on Branch1 do the following 之后,您仍然在Branch1执行以下操作

git checkout Branch2
git rebase -

important note make sure before doing git rebase - you were on the branch you need to rebase. 重要说明,请确保在执行git rebase -之前git rebase -您位于需要重新设置基准的分支上。 In this case it's Branch1 . 在这种情况下,它是Branch1 if you changed branches why so ever first go back to Branch1 so like this: 如果您更改了分支机构,为什么要先回到Branch1 ,如下所示:

git checkout Branch1
git checkout Branch2
git rebase -

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

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