为什么我的.csproj文件在git rebase之后搞砸了?

Mar*_*lle 14 .net git csproj git-rebase

在使用GIT进行源代码控制的.NET C#项目中,我在重新定位后不断收到格式错误的csproj文件以获取最近提交的代码.这是我的过程:

  1. 提交我的代码
  2. 构建并运行测试
  3. 重新定义为"最新"
  4. 诅咒天堂,因为csproj文件搞砸了...再次

这是rebase的输出:

D:\GitHub\AwesomeProject>git rebase master
First, rewinding head to replay your work on top of it...
Applying: added getstatus call
Using index info to reconstruct a base tree...
M       Host/Host.csproj
M       Host/packages.config
M       Trees/Trees.csproj
M       Trees/packages.config
M       UnitTests/UnitTests.csproj
<stdin>:1229: trailing whitespace.
  <!-- To modify your build process, add your task inside one of the targets bel
ow and uncomment it.
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging UnitTests/UnitTests.csproj
Auto-merging Trees/packages.config
CONFLICT (content): Merge conflict in Trees/packages.config
Auto-merging Trees/Trees.csproj
Auto-merging Host/packages.config
CONFLICT (content): Merge conflict in Host/packages.config
Auto-merging Host/Host.csproj
Failed to merge in the changes.
Patch failed at 0001 added getstatus call

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".
Run Code Online (Sandbox Code Playgroud)

有冲突,但你可以看到它自动合并csproj文件,它做错了!! csprojfile的XML无效,项目无法加载.这是一个简单的概述:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  ... most of one version the project file
  <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  ... most of the other version the project file
  <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
</Project>
Run Code Online (Sandbox Code Playgroud)

为什么会这样?我怎样才能改进处理它的过程?

don*_*ngg 18

您可能希望使用.gitattributes文件来使用稍微不同的合并驱动程序.我发现这有助于我的:

*.csproj -text merge=union
*.sln -text merge=union
Run Code Online (Sandbox Code Playgroud)

您可以在这里阅读更多相关信息,看看是否有更好的选择.

你也可以告诉git花一点时间考虑它与这样的patience选项的合并:( 在这里阅读更多)

git rebase -s recursive -X patience
Run Code Online (Sandbox Code Playgroud)

我能想到的唯一另一件事是确保你经常提取代码,以便git必须做的合并更小.

仅供参考,如果你愿意,你可以做一个rebase关于在你做一拉像这样同一时间在同一行:(你还可以通过在recursivepatience选项都是相同的)

git pull --rebase origin master
Run Code Online (Sandbox Code Playgroud)

  • 对于那些阅读一年以上的人,您应该从Github开发人员那里查看这篇文章:http://haacked.com/archive/2014/04/16/csproj-merge-conflicts/ (12认同)