Alex
Alex

Reputation: 7622

Git modifies a file as it thinks it should, but I think it does it wrong

I have 2 separate branches and a file that has been changed on both these branches (separate histories after a certain point - let's just blame an anonymous developer for this misuse of git).

The problem I have is that when merging these 2 branches, git automatically modifies the file.

It doesn't consider that file to be under merge conflict (which would be great as I would be able to fix it up myself and choose parts from both that I want to keep).

In the end it seems like git prefers one version over the other, as whenever I merge I lose some methods from one of the branches.

Any ideas what I should do to overwrite this git functionality and be able to compare those 2 versions of the file and selectively choose what I want the end file to look like?

Or other ideas about what I should do?

Upvotes: 0

Views: 58

Answers (2)

twalberg
twalberg

Reputation: 62519

When git merges two files, if the areas that were changed on the two parent branches do not overlap, it can usually automatically add the changes from both sides into the new file without conflicts. In this case, you have a couple options:

  • You can git merge --no-commit, to give you a chance to review the changes made, and make any adjustments necessary before you then do a manual git commit to complete the merge.
  • If you know that the changes made on the other end are bogus, and you want to completely ignore them, you can use git merge -s ours to keep your version of the file.

Another thing to be aware of is gits rerere mechanism, which is not usually enabled by default, I think. But if it is, it takes notice of manual conflict resolutions, and, if it ever sees that particular conflict show up again, will automatically apply the same resolution. If that's the case, you would probably want to use git merge --no-commit, like in the first case, so you could check to make sure you have the desired outcome before you commit.

Upvotes: 1

Bipul Sinha
Bipul Sinha

Reputation: 266

Git performs Pull and Push so it normally performs this operation for full repository rather than single/selected file(s). So, if it is not a merge conflict it will simply merge the changes or will replace one from another if you are performing a PULL operation.

So possible way is perform synchronize or compare from other branch and manually merge your file.

Upvotes: 0

Related Questions