Dot-Net
為什麼我的 .csproj 文件在 git rebase 後變得混亂?
在一個使用 GIT 進行原始碼控制的 .NET C# 項目中,我在重新定位以獲取最近送出的程式碼後,不斷收到格式錯誤的 csproj 文件。這是我的過程:
- 送出我的程式碼
- 建構和執行測試
- 變基以“獲取最新”
- 詛咒天堂,因為 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>為什麼會這樣?以及如何改進我的流程來處理它?
您可能希望使用 .gitattributes 文件來使用稍微不同的合併驅動程序。我發現這對我有幫助:
*.csproj -text merge=union *.sln -text merge=union您可以在此處閱讀有關它的更多資訊,看看是否有您更喜歡的選項。
您還可以告訴 git 多花一點時間考慮它與這樣的
patience選項的合併:(在此處閱讀更多內容)git rebase -s recursive -X patience我能想到的唯一另一件事是確保您經常提取程式碼,以便 git 必須做的合併更小。
僅供參考,如果你願意,你可以
rebase在同一行同時做一個這樣的拉動:(你仍然可以傳遞相同的recursiveandpatience選項)git pull --rebase origin master