Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In git merge conflicts, how do I keep the version that is being merged in?

I have two local git branches on my machine - a branch called "v2" and a branch called "master". I'm merging v2 into master while master is checked out and the head branch.

I'd like to merge the "v2" branch into the "master" branch. When I perform the merge, there are a number of conflicts that I must resolve one by one.

For each conflict, how do I keep the "v2" branch file and not the "master" branch version of the file?

The options presented to me by Git Tower for these types of conflicts are:

  • Mark FILENAME as Manually Resolved
  • Resolve by Keeping FILENAME
  • Resolve by Deleting FILENAME
  • Restore Their Version of FILENAME
  • Open in External App

From my understanding, the option to "keep" the file meant keeping the "v2" version (the one being merged in) and "deleting" the file meant not adding the "v2" version (but instead keeping the existing "master" version). When I used the delete option, though, it actually deleted the file altogether from the repo.

How do I keep the "v2" branch file and not the "master" branch version of the file for these types of conflicts?

like image 877
Tim Jahn Avatar asked Dec 14 '12 19:12

Tim Jahn


People also ask

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.


Video Answer


1 Answers

Even though you are using Git Tower, you can drop down to the command line and use

git checkout --theirs file.txt

Here some docs about it:

http://gitready.com/advanced/2009/02/25/keep-either-file-in-merge-conflicts.html

If you want to ONLY use git tower, complete the merge as is, then checkout the other branch's version of that file. Now stage and commit with amend - if possible.

Git has been developed to be a command line tool. With every other tooling that I've ever used, I always had a gap in functionality. I chose to embrace instead of fight the design of Git.

Also, you could hook up something like Beyond Compare and choose "external tool" as is mentioned in your question. There, you will have an option to choose the "theirs" side.

like image 72
Adam Dymitruk Avatar answered Oct 21 '22 16:10

Adam Dymitruk