【问题标题】:Why are my .csproj files getting messed up after a git rebase?为什么我的 .csproj 文件在 git rebase 后变得混乱?
【发布时间】:2012-11-20 18:01:26
【问题描述】:

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

  1. 提交我的代码
  2. 构建和运行测试
  3. 变基为“获取最新”
  4. 诅咒天堂,因为 csproj 文件被搞砸了......再次

这是变基的输出:

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".

存在冲突,但正如您所见,它自动合并了 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>

为什么会这样?以及如何改进我的流程来处理它?

【问题讨论】:

    标签: .net git git-rebase csproj


    【解决方案1】:

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

    *.csproj -text merge=union
    *.sln -text merge=union
    

    您可以阅读更多关于它的信息here,看看是否有您更喜欢的选项。

    您也可以告诉 git 多花一点时间考虑它与 patience 选项的合并,如下所示:(read more here)

    git rebase -s recursive -X patience
    

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

    仅供参考,如果你愿意,你可以在同一行同时执行一个 rebase,就像这样:(你仍然可以传递 recursivepatience 选项相同)

    git pull --rebase origin master
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-07
    • 2012-10-23
    • 2019-09-11
    • 1970-01-01
    • 2011-09-11
    • 2014-11-01
    • 2020-06-08
    • 1970-01-01
    相关资源
    最近更新 更多