I want to merge all files manually with meld or any other diff tool, how can I do this with Git?
When I run git mergetool
it says no
I found the other answers unsatisfactory and became frustrated searching for an answer. A solution to this question I finally found here: https://stackoverflow.com/a/11593308/1351182
If you run these commands, you will create a new commit which essentially takes the latest commit of branchToMergeFrom
and allows you to apply a patch on top of it, which I think is like an additional commit on top.
git checkout branchToMergeTo
git checkout --patch branchToMergeFrom [file]
You will then be prompted (file-by-file if you didn't specify file
) on exactly which 'hunks' you want to merge. In this way it walks you through each part of what would have been the automatic merge process and instead asks for manual arbitration on which bits and pieces you want to accept from the mergefrom
branch. Here's an example of what it looked like in my project:
@@ -249,7 +251,8 @@ def draw_everything():
draw_bg()
draw_balls(ax)
- plt.show(block=False)
+ if show:
+ plt.show(block=False)
def advance(ms, accel_fun, collision_matrix_fun):
global balls
(3/6) Apply this hunk to index and worktree [y,n,q,a,d,K,j,J,g,/,e,?]?
After typing y
and
, I was presented with the next hunk, (4/6)
for that file. This prompt at the bottom lets you simply accept the merge 'hunk' with y
, reject it with n
, or even go in and edit it manually. Here are the options:
y - apply this hunk to index and worktree
n - do not apply this hunk to index and worktree
q - quit; do not apply this hunk or any of the remaining ones
a - apply this hunk and all later hunks in the file
d - do not apply this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
I wanted to go in and manually edit one hunk, as I didn't want to accept or reject the merge exactly as it was posed. So I chose e
and was given a file to edit. I was pleased when I noticed there were even instructions at the bottom on how to edit the hunk properly. You can even split hunks into smaller ones with the s
option as above.
I would recommend this process if what you want is manual merging where you still leverage the automatic process as much as possible. The difference is that you get to oversee every merge 'hunk' and edit them as you please. I hope this helps future readers.
After this process, you probably want to run git checkout branchToMergeTo && git merge branchToMergeFrom
in order to formally merge the history of branchToMergeFrom
into branchToMergeTo
.