user4363553
user4363553

Reputation: 103

Resolve a VS2017 GIT merge conflict

Trying to get a GIT workflow to work but have hard time using the VS2017 (v15.4.2) GIT UI.

These are my steps:

This will create a merge conflict. However, the merge conflict cannot be resolved without creating an invalid Class1 file. It does not seem possible to only add the Feature1 method to the existing Class1 file as it also inserts the using statements and the class definition to it.

How do I add only the added Feature2 method to the existing Class1? Am I missing something obvious here?

Thank you for your time.

Upvotes: 4

Views: 3349

Answers (2)

jamill
jamill

Reputation: 1732

You can "Merge" the conflicting files in Visual Studio and edit the merged version before completing the merge. On the Resolve Conflicts page, you should be able to select the conflict and merge it. After working through the conflicts, you can accept the result (editing the resolved content, if necessary).

You should see a UI similar to the following: Merge conflicting file

Does this allow you to resolve the conflict as expected (and successfully)?

Upvotes: 1

ThePretendProgrammer
ThePretendProgrammer

Reputation: 1517

Unfortunately, resolving merge conflicts in Visual Studio is not an ideal experience as of now. The two copies are compared on the basis of their commits and their corresponding hashes. Given that two files might look identical and still could originate from two different commits having different hashes, Visual Studio finds it difficult to resolve such commit. You have two options in this case:

  1. Manually copy the Feature2 method and add it to your working copy in feature1 branch and then try to merge this branch to master. You will again face a merge conflict, but Visual Studio provides you with an option to eithertake source or take target. In this case, you can take source which corresponds to your feature1 branch, since you know for a fact that this branch has all the required changes, and you can ignore the conflicts that master has to offer.
  2. Install Tortoise Git. You can also opt for any other reputable git client out there. Such clients will detect changes that are identical and automatically resolve merge-conflicts, the kind of which you are suffering from here.

Upvotes: 0

Related Questions