*.csproj
and similar files..csproj
file in a branch and then merge it with another branch, then you will probably encounter more merge conflicts than you might have had before.union
to merge *.csproj
files.git merge-file
documentation describing this function:Instead of leaving the conflict in a file, resolve conflicts in favor of our (or them or both) parties.
.gitattributes
file, so if you really want to use this behavior for your repository, add the following: *.csproj merge=union
foo.csproj
file in our master
branch along with the .gitattributes
file: <?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <Page Include="AAA.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="DDD.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> </PropertyGroup> </Project>
git init . git add -A git commit -m "Initial commit of gittattributes and foo.csproj"
git checkout -b branch
) under the original name “branch” and insert the following slice into foo.csproj
between the AAA.cs
and DDD.cs
. <Page Include="BBB.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page>
<?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <Page Include="AAA.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="BBB.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="DDD.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> </PropertyGroup> </Project>
git commit -a "Add BBB.cs element"
git checkout master
<Page Include="CCC.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page>
<?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <Page Include="AAA.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="CCC.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="DDD.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> </PropertyGroup> </Project>
git commit -a "Add CCC.cs element"
branch
into master
branch git merge branch
<?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <Page Include="AAA.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="CCC.cs"> <Page Include="BBB.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="DDD.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> </PropertyGroup> </Project>
.gitattributes
file in the repository and using the standard merge approach, the standard merge command resulted in a merge conflict that needs fixing. In our understanding, this is better than a blatant mistake that will remain in your project. <?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <Page Include="AAA.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <<<<<<< HEAD <Page Include="CCC.cs"> ======= <Page Include="BBB.cs"> >>>>>>> branch <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="DDD.cs"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> </PropertyGroup> </Project>
*.csproj
every time I add a file to a project..csproj
files, can we say that, although it is not an excellent one, it is a good enough solution to control ordinary merge conflicts? Maybe.:trollface:
Source: https://habr.com/ru/post/221999/
All Articles