Merge old git with HEAD on master

I made some mistakes when merging with my colleagues. Now we have discovered this, and we need to apply the old commit again to manually select the changes in the files. The situation looks like this:

A--\ /--F--\ C--D--E H--I B--/^ \--G--/ ^ | | WRONG MERGE MASTER 

I need git to ask me to combine B with I again, for example, B has never been in history. In other words, I need git to ask me to choose a merge for all files that differ in B and I commit. What is the best approach to such work? Can I achieve this with a cherry fence? How?

+7
source share
4 answers

Well, I finally decided so. I created a diff from B (against master, I in my example) and manually applied all the changes to mild difftool:

 [master]$ yes | git difftool <B hash> -t meld 

Then all modified files are added and committed.

+1
source

You can use the deal duplication trick:

 # make a branch named B started on the commit B git checkout -b B <sha1 id of the commit B> # it creates a branch which starts at a commit # right before B and has exact copy of commit as B, # but with a different sha1 id. git rebase --no-ff HEAD~1 # now we do simple merge git checkout master git merge B 

It also allows you to do a trick with a range of commits and saves dates, authors, commit messages, etc.

In fact, your script is described in the documentation :

--no-ff ... recreates the topic branch with fresh commits so that it can be successfully deleted.

+4
source

You can uncomment the merge using git revert -m 1 <commit> , and then just use git merge <B_branch> again. This will add a refund to your story. Otherwise, you can use git rebase -i to remove B from the story. The latter is more disruptive to collaboration, because all WIP and all collaborators will now have to reset their master branches.

If you don't mind undoing the commit, I highly recommend it. This is the easiest way to get what you want. If D, E, F, G, H or I are based on sets of B changes, then returning can be difficult.

+1
source

The wizard is supposed to be verified.

 git branch temp <sha1 of B> 

create a link to the old latch.

 git rebase --preserve-merges -i <sha1 of A> 

then pull out the first row to be merged.

Now all you need to get your B back is

 git merge temp 
+1
source

All Articles