Git Interactive Merge?

I have two branches with the same file (if you want it to be a .sql file), and I want to merge it interactively.

To a large extent, I want to open the diff program, as I do when there is a conflict (or command line), and choose which lines go there.

Is there any way to do this?

+64
git version-control
Jun 07 '12 at 15:44
source share
6 answers

Yes, but basically it will be done manually. You will tell Git that you are merging the two corresponding branches, but should not try to fix the result yourself (edited to add: or fast forward if it considers the merge to be trivial):

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

Then you ask Git for the file how it appeared in two branches:

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

and their merger base,

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

You combine them using any tool you want (for example)

 meld filename.{HEAD,branch,base} 

you do this ( git add filename ) and then copy the merge ( git commit ).

+61
Jun 07 2018-12-12T00:
source share

The easiest way is to make git merge <other_branch then git mergetool to graphically resolve conflicts. See # 10935226 how to configure mergetool.

The bottom line is that your modified file can quickly merge with the older one. Then you should be a little smarter.

A novocrates gives a great way to dig a little deeper, but you often have to change the initial command to git merge --no-commit --no-ff <other_branch> because --no-commit really means "don't commit" the merge ... if only it's not a quick merge. "It's a little pity for many people trying to do exactly what you want.

Sometimes the least confusing way is not very stylish: check another branch in a different working copy, use your favorite merge tool to get the right version in the right directory, and then commit it.

+37
Jul 19 '13 at 20:06 on
source share

According to this entity, where temp may be an existing branch.

https://gist.github.com/katylava/564416




According to the master:

 git checkout -b temp 

By time:

 git merge --no-commit --no-ff refactor 

... which puts everything, so that:

 git reset HEAD 

Then start adding the pieces you need:

 git add --interactive 
+25
Mar 13 '14 at 22:24
source share

From the branch you want to join to:

 git checkout -p branch_to_merge -- 

This will not check branch_to_merge, but will allow you to interactively add hunks from the patch (diff).

http://git-scm.com/docs/git-checkout

+19
May 27 '15 at 20:37
source share

You can simply use WinMerge , DiffMerge, or any available demarcation / merge tool to do the work manually. If you want to connect it to "git difftool", you can search the Internet to find ways to make these tools work with git.

+1
Jun 07 2018-12-06T00:
source share

The best way to do this is:

  1. Make a branch with your changes
  2. Create a new branch from this point
  3. Drop the commit in your new branch that you want to compare with and based on. The reset will be a "mixed" default reset, which means that it will not change the "working tree", that is, the actual code files
  4. At this point, my text editor (VSCode) shows me what is different between my current files and the commit to which I am reloaded. I can edit the code to select which lines I want to commit. This allows me to see all the changes in my branch and confirm every line of code that I will commit. This is useful, for example, before combining my changes into production.
0
Jan 12 '18 at 2:09
source share



All Articles