How do I prevent an automerge using Git?

I can see you may wish to do this if you do not trust auto-merge, because two edits in different places in a file (which are done on different branches) may not cause auto-merge to raise a conflict but may not actually work together.

You may want to look at using a custom merge driver. This page describes how to go about it.

Git - how to force merge conflict and manual merge on selected file

An alternative would be to find the files that differ between the branches first, before performing the merge, then checkout the file into the appropriate branch to ensure you get a clean merge and functional code that contains either one or the other of the two edits.

git diff --name-only <branch1> <branch2> 
git checkout <branch1> -- <paths>

git merge --no-commit --no-ff <local-branch>

does it.

When you executed it, the changes from local-branch are applied but not yet staged.

Then, you could look at the changes to be applied and –  in case that you want to take them all  – apply them with

git commit -a 

Otherwise, select the files to be taken, stage them with git add and finally commit them with git commit. Restore the unwanted files then with git checkout -- filename.


You are trying to bypass Git from getting involved in the merge process and to hand-pick each line of each modified file to be merged. This not the same as git cherry-pick. Neither will git merge --no-commit, etc. help. You will need to do:

$ git checkout master
$ git difftool -t kdiff3 local-branch HEAD

In the KDiff3 window, the left hand side (A) is your local-branch and the right hand side (B) is your current branch (master).

Select Merge | Merge Current File from the menu (or press the colorful diamond shaped icon with the same title).

You will then be shown a diff and conflicts (if any) for each file. And you will have the ability to pick left or right side (A or B), or both, and/or manually tweak the merged file.

On another note, something is telling me you have some bigger issues with your workflow.

Tags:

Git