4

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

These are my steps:

  • Creating a new WinForms project named Test and creating a local repository for it.
  • Create a branch from the master branch named feature1
  • Create a branch from the master branch named feature2
  • Activate feature1 branch add a class named Class1 and add a method named Feature1 to it
  • Commit the changes
  • Activate feature2 branch add a class named Class1 and add a method named Feature2 to it
  • Commit the changes
  • Merge the feature2 branch onto the master branch (the master branch now has Class1 with method Feature2)
  • Merge the feature1 branch onto the master.

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.

user4363553
  • 103
  • 1
  • 8

2 Answers2

1

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)?

jamill
  • 1,682
  • 13
  • 9
0

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.
ThePretendProgrammer
  • 1,449
  • 10
  • 16