Revert any branch-specific changes so that the branch reflects master

Is it possible to revert all the changes made to a specific branch without losing history?

I forked master a long time ago to hide certain features, but now this branch should be the same as master, but I need branch history intact.

master -> branched -> (revert stripping) -> branched = master

The forked one should now reflect the master , although I want to commit to the forked one with all the changes that are necessary to go to the master .

The easiest way I can think of is to copy the master sources and delete / paste the files into the forked one , but I'm worried if this would cause conflicts when I later merge from master?

+3


source to share


2 answers


Edit:

The solution from Preuk doesn't work for me (Git 2.2.1), but these commands work:

$ git checkout branched
$ git revert -n master..branched
$ git commit -m "Revert to master"

      



Original message:

I would suggest using git format-patch

followed git am

on a dedicated branch, squash a commit with git rebase -i

, and then apply the result on the branch branched

:

  • Create a new branch starting at branched

    :

    $ git checkout branched
    $ git checkout -b tmpbranch
    
          

  • Apply canceled commits between master

    and branched

    :

    $ git format-patch -R master..branched --stdout | git am
    
          

  • Combine commits into one:

    $ git rebase -i branched
    $ # Use the squash command for all commits except the first one
    $ # and set the log message to "Revert to master" for instance.
    
          

  • Then merge and delete the temporary branch tmpbranch

    to branched

    :

    $ git checkout branched
    $ git merge tmpbranch
    $ git branch -d tmpbranch
    
          

+1


source


You can try going back and reinstalling the master in squash mode.

First, you will need to undo the commit that is specific to your branch from its beginning. To do this, use something like this :

git revert OLDER_COMMIT^..NEWER_COMMIT

      



Then you will get 1 commit on your satellite branch with all changes from master after branching.

git checkout topicbranch
git rebase -i master

      

and select squash for each commit.

0


source







All Articles