How do I force a rebase when the same changes are manually applied to both branches?

My repository looks like this:

X - Y- A - B - C - D - E             branch:master
     \                  \
      \                  \ merge master -> release
       \                  \
        M  ---  BCDE  ---  N         branch:release 

      

Here the "M-BCDE-N" manually (unfortunately!) Applies the changes in much the same way as the individual "ABCDE" commits (but GIT doesn't seem to know that these changes are the same). I would like to reinstall and get the following structure:

X - Y- A - B - C - D - E     branch:master
                        \
                         *   branch:release 

      

those. I want to make a branch: release will be exactly the same as branch: master and fork is from the main HEAD.

But when I run the "git rebase master" sitting in the branch release, GIT reports a lot of conflicts and returns rebasing. How can I solve this?

Another explanation for this: I would like to "recreate" the branch: free from scratch from the master HEAD. And there are many other people who have already done a "git pull" for the: release branch, so I cannot use GIT reset + GIT push -f.

+2


a source to share


2 answers


You say people have already pulled the release branch, so you can't reset. This also means that you cannot rebase - anyway, you move the ref in non-merge mode and frustrate everyone else.

Assuming you want to dump everything on the release branch (I'm a little confused M

) and make it identical to master (why are you showing *

?), Here's what you can do:

git checkout master
git merge --strategy=ours release   # merge in release, but keep master contents
git checkout release
git merge master                    # fast-forward

      

As a result, you get the following:

X - Y- A - B - C - D - E ----- Z (master, release)
     \                  \     /
      \                  \   /
       \                  \ /
        M  ---  BCDE  ---  N

      



Reconciling a merge Z

will undo all changes from the release; it's just to ensure that the release is moving forward. From the documentation:

our

This allows any number of heads, but the resulting merge tree always refers to the current branch of the branch, effectively ignoring all changes from all other branches. It is intended to replace the old history of the development of side branches.

This is exactly your situation!

It is also a good idea to use the parameter --no-commit

in the merge and then manually so that you can edit the message and mark what you did.

+1


a source


You can use git rebase -i master

and remove the line for BCDE

to ditch this version entirely. If it is truly identical A-B-C-D-E

, then you shouldn't have a problem.



0


a source







All Articles