简体   繁体   中英

Pushing a sub-branch without rebasing

Say we have this topology:

X--X--X--             origin/master
    \     
     \     
      \--X--X--X--             b1 (private - not to be shared)
             \
              \
               \--X--X--X--    b2 (to be shared upstream)

We want to share only b2 but not b1, so we can do:

git rebase --onto origin/master b1 b2
git push origin b2

Is it possible to achieve the same goal without using rebase and changing local history? (pushing b2 sans b1 commits)

No, that's not possible. Some b1 commits are in b2 's history, so you'll have to rewrite history to get rid of those.

It helps to think not of individual files, but of the commit objects as a whole. To get to b2, you need some of the commit objects from the second line.

A--B--C--                  master
    \
     \--D--E--F--          b1
            \
             \--G--H--I--  b2

In order to get the I commit, you need all the commit objects A, B, D, E, G, H, I.

So unless you rebase G from B you will not be able to exclude the D, E commits.

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