Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Interactive Merge?

I have two branches with the exact same file (incase you are wondering it is a .sql file) and I want to interactively merge it.

Pretty much I want to open up a diff program like I do when there is a conflict (or command line) and select exactly what lines go where.

Is there anyway to do this?

like image 686
Steven Avatar asked Jun 07 '12 15:06

Steven


People also ask

What is interactive merge?

The interactive approach to merging two branches together (safely) is incrementally in steps that allows for manual fixing. Some call this “rebase with history” because the technique creates new commits based on previous commits like rebase, but retains the previous commit history (which rebase currently does not do).

What are the different types of git merge?

Git merging combines sequences of commits into one unified history of commits. There are two main ways Git will merge: Fast Forward and Three way. Git can automatically merge commits unless there are changes that conflict in both commit sequences.


1 Answers

Yes, but it will mostly be by manually making that happen. You'll tell Git you're merging the two relevant branches, but that it shouldn't try to commit the result on its own, (edited to add: nor fast-forward if it thinks the merge is trivial):

git merge --no-commit --no-ff branch-to-merge 

Then you'll ask git for the file as it appeared in the two branches:

git show HEAD:filename >filename.HEAD git show branch-to-merge:filename >filename.branch 

and their merge base,

git show `git merge-base HEAD branch-to-merge`:filename  >filename.base 

You'll merge them using whatever tool you want (e.g.)

meld filename.{HEAD,branch,base} 

you'll stage that (git add filename), and then commit the merge (git commit).

like image 90
Phil Miller Avatar answered Sep 23 '22 03:09

Phil Miller