📂
JackyChen的精神時光屋
  • About
  • iPlayground
    • iPlayground 2020
      • iPlayground submit 2020
    • iPlayground 2019
      • Untitled
      • iPlayground submit 2019
  • WWDC
    • 2020 WWDC
    • 2019 WWDC
    • 2018 WWDC
      • What's New in Testing
      • BusinessChat
    • 2016 WWDC
      • What's New in the Apple Push Notification Service
  • AR/VR
    • ARKit plugin at Unity
    • ARKit
    • AR/VR 實習作品分享
    • Google Blocks
  • CI/CD
    • Continous Integretion for Unity
    • 拯救地球大作戰-自動化設定注意事項
    • Provisioning Profile 自動化更新
    • Make ipa file with personal team of code sign
    • Xcode11 版號問題
  • Test
    • Cucumberish
    • XCUITest
    • Design Patterns in XCUITest
    • Unit Test
  • User Interface
    • IBDesignable 和 IBInspectable
    • iOS 使用貝塞爾曲線繪製路徑
    • UIStatusBarStyle
    • iOS Devices Specification
    • Vector Image
    • Launch Screen
    • Haptic Feedback
    • Good Works for Storyboard
    • Cell 展開收合效果
    • ScrollView
    • Swift lazy
    • Lottie
  • Foundation
    • Adding a Custom Font to Your App
    • WKWebView how to work with javascript
    • Global Central Dispatch
    • HealthKit
    • Error Handling
    • Debug with LLDB
    • Application Lifecycle
    • Swift Codable
    • Push Notifications
    • AVFoudation
  • Others
    • C語言指標概念
    • UnsafePointer(Swift)
    • iOS News Reference
    • Blender
    • Free Web Server
    • Firebase
    • Firebase migration
    • GraphQL
    • Ruby
    • zsh command line
    • visudo
  • Security
    • 課程:App資安規劃與實作
    • KeyChain
    • iOS反組譯程序
    • Arxan
  • Git
    • Git
    • xcodeproj 合併衝突
    • Pull Request
  • Machine Learning
    • CoreML
    • Vision
    • Turi Create
  • 待分類
    • ABI Stability and More
    • Mirror
    • Carthage
    • SwiftUI
    • MVVM
    • OpenSSL
    • USDZ Convert
    • Nexus repository and gitlfs
Powered by GitBook
On this page
  • 20200121
  • 20190218 issue

Was this helpful?

  1. Git

xcodeproj 合併衝突

PreviousGitNextPull Request

Last updated 5 years ago

Was this helpful?

20200121

  • 最後參照大神做法,對 pbxproj 做 sort

20190218 issue

  • 在 Xcode10 的環境下,若有兩個 feature 分支同時對檔案新增資料夾,在合併到本支後,下面的所有工具及設定都無法完美的解決衝突問題,最慘的狀況還會造成專案無法打開

  • 目前的研究,應該是 pbxproj 在合併之後,檔案結構不正確所造成

6D422F9B221A52BE003CDA51 /* ha2-1 */ = {
        isa = PBXGroup;
        children = (
                6D422F9C221A52D1003CDA51 /* ha2-1.swift */,
        );
        path = "ha2-1";

        sourceTree = "<group>"; <-- 合併後會少了這行
}; <-- 合併後會少了這行

6D422F9E221A52F1003CDA51 /* ha2-2 */ = {
        isa = PBXGroup;
        children = (
                6D422F9F221A5309003CDA51 /* ha2-2.swift */,
        );
        path = "ha2-2";

        sourceTree = "<group>";
};
  • 即使在不使用任何手段的狀況下,試圖手動去解決衝突(刪除 <<<<< HEAD 等標記符號),仍然會產生如上述檔案結構不正確的結果,推論這應該是 git 不知如何正確處理 pbxproj 所導致,和用什麼工具及設定無關

  • 目前還是決定使用 *.pbxproj merge=union 的作法,必須注意

    • 就目前研究來看,增減檔案沒有問題

    • 專案的資料夾不可任意增減

    • 遇到專案無法打開,密切注意PBXGroup結構是否不正確,並手動修正

      /* Begin PBXGroup section */
    • 1. Create a .gitattributes file

      Assuming you don’t already have one, create a file called .gitattributes in your project’s root directory.

    • 2. Set the merge strategy to union

      Add the following line to your .gitattributes file:

      *.pbxproj merge=union

      This will tell git to merge using the union strategy, meaning it’ll keep both sides (theirs and ours) during a merge. This is almost always what you want in the case of a *.pbxproj merge conflict.

    • 3. Add the .gitattributes file to git and push your changes

      Now that your merge strategy is set, make sure to give the rest of your team this wonderful gift. Add the .gitattributes file to your git repo:

      git add .gitattributes
    • 手動解決

      • 如果合併後發生衝突,可執行以下指令(手動用)

        git mergetool --tool=mergepbx [你的專案名稱].xcodeproj/project.pbxproj
      • 但在執行上述指令前,須先在 ~/.gitconfig 加入以下設定

        [mergetool "mergepbx"]
        cmd = mergepbx "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"
    • 自動解決

      • 如果想合併後自動解決衝突,可在~/.gitconfig 加入以下設定

        [merge "mergepbx"]
        name = XCode project files merger
        driver = /usr/local/bin/mergepbx %O %A %B
      • 在專案目錄下,新增 .gitattributes,並加入以下內容

        *.pbxproj merge=mergepbx
    • 補充:pre-commit 內容如下

      #!/bin/sh
      PATH=$PATH:/usr/local/bin  # 加這行 SourceTree 才能正常執
      xunique CathayHospital.xcodeproj
    • 記得修改 pre-commit 權限

      chmod 755 .git/hooks/pre-commit

讓 Xcode 專案易於版本控制的方法
參考連結
Automatically resolving git merge conflicts in Xcode’s project.pbxproj file
mergepbx
xUniqe