简体   繁体   中英

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.

I expected something like this to happen.

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

But on running git log on Branch1, it shows:

a -- x

and on running git log on Branch2, it shows:

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.

So my question is, How do I squash those 2 commits properly such that it is reflected in all branches?

Also how do I fix up once I already did that?

Now I checkout to branch1 and squash commits b and c into x.

after that you still are on Branch1 do the following

git checkout Branch2
git rebase -

important note make sure before doing git rebase - you were on the branch you need to rebase. In this case it's Branch1 . if you changed branches why so ever first go back to Branch1 so like this:

git checkout Branch1
git checkout Branch2
git rebase -

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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