Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent systematic conflicts when merging Visual C++ 2012 project filters?

When new files are added to a Visual C++ project, the IDE adds them in two locations:

  • The main project file (e.g. myproject.vcxproj)
  • The project "filters", a repository of the virtual paths of the solution explorer (e.g. myproject.vcxproj.filters)

Merging file additions is not a problem for the main project file, but it's very often a source of conflicts for the filters. The problem comes from the fact that the IDE always adds new elements at the very end of the filter list.

To illustrate the problem, let's say the filters initially look like this:

1 <ClInclude Include="fs\path\oldFile1.h">
2   <Filter>virtual\path</Filter>
3 </ClInclude>
4 <ClInclude Include="fs\path\oldFile2.h">
5   <Filter>virtual\path</Filter>
6 </ClInclude>

Then programmer A add newFileA.h and commits, the filters are updated as follows:

1 <ClInclude Include="fs\path\oldFile1.h">
2   <Filter>virtual\path</Filter>
3 </ClInclude>
4 <ClInclude Include="fs\path\oldFile2.h">
5   <Filter>virtual\path</Filter>
6 </ClInclude>
7 <ClInclude Include="fs\path\newFileA.h">
8   <Filter>virtual\path</Filter>
9 </ClInclude>

If programmer B also adds a newFileB.h and is note synced on the head revision, his local copy of the filters will look like this:

1 <ClInclude Include="fs\path\oldFile1.h">
2   <Filter>virtual\path</Filter>
3 </ClInclude>
4 <ClInclude Include="fs\path\oldFile2.h">
5   <Filter>virtual\path</Filter>
6 </ClInclude>
7 <ClInclude Include="fs\path\newFileB.h">
8   <Filter>virtual\path</Filter>
9 </ClInclude>

Trying to sync with the changes of programmer A will systematically provoke a merging conflict on lines 7-8-9 for programmer B. That's because the changes happen to occur at the exact same spot.

Is there a way to prevent this issue from happening, be it through a config change in Visual Studio, a special option of some merging tool (preferably Araxis Merge or Beyond Compare), or anything else?

like image 250
Laurent Couvidou Avatar asked Oct 11 '13 14:10

Laurent Couvidou


1 Answers

Base upon this question, it sounds like filters are not necessary for Visual Studio to function. Have you tried simply not committing in your filter files, and instead having everyone have their own file? I don't use VS, so I don't know what those files do, or what functionality wouldn't be synchronized. However, I generally don't recommend committing in IDE specific files, as they generally change for different users, and are just a source of conflicts anyways.

like image 84
MJD Avatar answered Nov 09 '22 10:11

MJD