Подтвердить что ты не робот

Почему мои файлы .csproj перепутались после git rebase?

В проекте .NET С#, который использует GIT для управления версиями, я продолжаю получать неверные файлы csproj после перезагрузки, чтобы получить последний коммандовый код. Это мой процесс:

  • передать мой код
  • создавать и запускать тесты
  • rebase для получения последней информации
  • проклинает небеса, так как файл csproj прикручен... AGAIN

Здесь вывод на 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".

Есть конфликты, но, как вы можете видеть, они автоматически скомпилировали файлы csproj, и они сделали это неправильно! XML файл csproj недействителен и проект не загружается. Здесь урезанный вариант того, как он выглядит:

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

Почему это происходит? И как я могу улучшить свой процесс, чтобы справиться с этим?

4b9b3361

Ответ 1

Возможно, вы захотите использовать файл .gitattributes, чтобы использовать немного другой драйвер слияния. Я обнаружил, что это помогло мне:

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

Вы можете прочитать об этом здесь, чтобы узнать, есть ли варианты, которые вам больше нравятся.

Вы также можете сказать git немного подумать о своих слияниях с параметром patience следующим образом: (подробнее здесь)

git rebase -s recursive -X patience

Единственное, что я могу придумать, это убедиться, что вы часто вытаскиваете код, чтобы сделать слияния git меньше.

FYI, если вы хотите, вы можете сделать rebase в той же строке, в то же время, что вы делаете это так: (и вы все равно можете пройти в параметрах recursive и patience одинаково)

git pull --rebase origin master