12

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?

Tim Jahn
  • 1,154
  • 7
  • 16
  • 29
  • dup: http://stackoverflow.com/questions/1823650/using-git-how-to-do-a-use-theirs-during-a-conflict – jchapa Dec 14 '12 at 19:56
  • I'm asking specifically related to the Git Tower client, in which case the link you provided does not answer my question. – Tim Jahn Dec 14 '12 at 19:59
  • Good point - sorry, I was providing the answer for git in general. – jchapa Dec 14 '12 at 22:27
  • 1
    If you are specifically asking about Git Tower, you should probably say that in the question. – ebneter Dec 15 '12 at 01:34
  • I would suggest looking at SourceTree by Atlassian. It is a far more capable GUI git client for Mac then Tower is. Plus it is free. – dbainbridge Jan 05 '13 at 03:23

2 Answers2

19

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.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • There is no option in Git Tower to checkout an individual file while reviewing the merge conflicts... – Tim Jahn Dec 14 '12 at 20:01
  • 1
    Just drop down to the command line to do it. Git's state is the same no matter what tool you're using. My recommendation is to use git from the command line. You get a lot of benefits: scriptability, piping, tab completion, session to session history, and others. – Adam Dymitruk Dec 14 '12 at 20:02
  • Unfortunately, that doesn't answer my question. I'm using Git Tower for a reason and am specifically asking how to do it within this application. – Tim Jahn Dec 14 '12 at 20:04
  • 1
    I don't think there is a way to do it through tower. Updating answer. – Adam Dymitruk Dec 14 '12 at 20:04
  • If you insist on using Git Tower and only Git Tower, perhaps you should ask the technical support folks at fournova to explain how to do it. – ebneter Dec 15 '12 at 01:38
7

If you're looking to keep v2 hands down (I want master to look exactly like v2), I think the easiest way is to:

  • Checkout the branch you want to merge
  • Merge master into the branch with the ours strategy
  • Checkout master
  • Merge the branch

It would look like this:

git checkout v2
git merge -s ours master
git checkout master
git merge v2

If you just want this type of resolution to happen only on conflicts, then you can do:

git checkout master
git merge -s recursive -Xtheirs v2

You can read up on merge strategies in the git documentation here.

UPDATE: unfortunately, I don't think Git Tower exposes a way to do this yet. :-(

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79