Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent an automerge using Git?

Tags:

git

I am trying to merge a local branch into the master branch without having Git to do an automerge. I would like to “hand pick” what I would like to be merged into master.

When I use Git’s difftool command, I am able to diff and select what I want to be added into the master branch. But then when I do a merge, I will lose what I selected prior because Git will do an automerge. I can commit the changes into master prior to the merge, but doing so seems unnatural.

And Git’s mergetool is only available when there are conflicts from a merge. But if Git does an automerge then usually there aren’t conflicts, so I am unable to run the mergetool command.

Update:

I am starting to think what I am trying to accomplish is bad practice or it’s just not possible. That is, to merge a topic branch and only have it merge what I need from diffing. And in an addition, to have this reflected in history. At any rate, the question I posted surfaced when experimenting with Git.

like image 823
marckassay Avatar asked Mar 08 '11 16:03

marckassay


People also ask

How do I stop git from auto merging?

Restore the unwanted files then with git checkout -- filename . @marckassy: But you could then git reset HEAD and git add -p to select what you want. To shut off the initial merge completely, add -s ours .

Does git pull auto merge?

Since your local commit isn't on the remote repository yet, when git pull runs git merge origin/[branch] [branch] , it will automatically do a "recursive" merge and create a commit with the remote changes.


2 Answers

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.

like image 41
eckes Avatar answered Oct 11 '22 10:10

eckes


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.

like image 134
FractalSpace Avatar answered Oct 11 '22 12:10

FractalSpace