Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make git automatically open the mergetool if there is a merge conflict?

How do I make git automatically run git mergetool for any merge conflict? This should apply for all merges, using merge, rebase, pull, etc.

like image 342
Matthew Flaschen Avatar asked Apr 05 '12 16:04

Matthew Flaschen


People also ask

How do I resolve merge conflict in Mergetool?

We can manually resolve the merge conflict by editing the content in the bottom pane, and then saving the file using :wqa (Write and Quit all files). Once the conflict resolution is successful, the merged file will be staged for commit. git commit -m 'Merged from multiple branches' .

Can Git automatically resolve merge conflicts?

A merge conflict is an event that takes place when Git is unable to automatically resolve differences in code between two commits. Git can merge the changes automatically only if the commits are on different lines or branches.

What happens if you get a conflict during a merge?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.


1 Answers

You cannot (yet) make git do this.


This may or may not be an acceptable workaround.

Create a function in your ~/.bashrc:

git()  {    if [[ $1 == "merge" ]] || [[ $1 == "rebase" ]] || [[ $1 == "pull" ]]; then      command git "$@"      rc=$?     if [[ $rc == 1 ]]; then       echo "There are conflicts, better run git-mergetool!!!"       # There might be some other condition that returns a '1',       # if so you can add another check like this:       # if grep Conflicts $(git --git-dir)/MERGE_MSG;       command git mergetool     fi   else      command git "$@"   fi } 

Mergetool isn't invoked when it merges:

$ git merge non_conflicting_branch Merge made by the 'recursive' strategy.  bar | 0  1 file changed, 0 insertions(+), 0 deletions(-)  create mode 100644 bar 

Mergetool is called when there are conflicts:

$ git merge conflicting_branch Auto-merging foo CONFLICT (content): Merge conflict in foo Automatic merge failed; fix conflicts and then commit the result. There are Conflicts, better run git-mergetool!!! 

Mergetool is not called on other errors:

$ git merge adasds fatal: adasds - not something we can merge 
like image 193
onionjake Avatar answered Oct 04 '22 08:10

onionjake