为什么我的.csproj文件得到搞砸了一个Git变基后?我的、砸了、文件、变基后

2023-09-03 09:21:10 作者:不将就

在一个.NET C#项目,它使用GIT的源代码控制,我不断收到重订基期后畸形的csproj文件,以获得最新COMMITED code。这是我的过程:

In a .NET C# project which uses GIT for source control, I keep getting malformed csproj files after rebasing to get the most recently commited code. This is my process:

在提交我的code 在建造和运行测试 变基得到最新的 诅咒天,作为的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是无效的,该项目不会加载。下面是它看起来像一个精简verstion:

There are conflicts, but as you can see it auto-merged the csproj files, and it did it incorrectly!! The XML of the csprojfile is not valid and the project doesn't load. Here's a stripped down verstion of what it looks like:

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

这是怎么回事?我怎样才能提高我的程序来处理呢?

Why is this happening? And how can I improve my process to deal with it?

推荐答案

您可能需要使用一个.gitattributes文件中使用略有不同的合并驱动程序。我发现,这有助于与我:

You may want to use a .gitattributes file to use a slightly different merge driver. I have found that this has helped with mine:

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

您可以阅读更多关于它这里,看是否有选择你更喜欢。

You can read more about it here to see if there are options you like better.

您也可以告诉git去稍长考虑其合并与耐心这样的选项:(在这里阅读更多)

You can also tell git to take a little longer thinking about its merges with the patience option like this: (read more here)

git rebase -s recursive -X patience

这是我能想到的唯一的另一件事是,确保你拉code往往使混帐必须做的合并更小。

The only other thing that I can think of is to make sure that you pull code often so that the merges git has to do are smaller.

仅供参考,如果你愿意,你可以做一个重订在同一时间,你做一拉像这样在同一行:(你还可以通过在递归耐心选项一样)

FYI, if you want you can do a rebase on the same line at the same time that you do a pull like this: (and you can still pass in the recursive and patience options the same)

git pull --rebase origin master