顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

[iOS]SourceTree error : 'yourXXX.git' does not appear to be a git repository

一個很久沒動的專案,簽入異動至server前,在pull時遭遇如下錯誤
Xcode






Source Tree

後來發現是Remote repository paths不知為何跑掉,參考下圖修改即可

CocoaPods could not find compatible versions for pod

最近開始用Swift 4開發,想當然third party也要用到最新,以Alamofire、PKHUD為例,我分別需要4.7版、5.0版

        根據Alamofire官方PKHUD官方pod file應該是
        pod 'Alamofire', '~>  4.7'
        pod 'PKHUD', '~> 5.0'










結果pod install會遇到如下錯誤
        [!] CocoaPods could not find compatible versions for pod "Alamofire":
        In Podfile:
           Alamofire (~> 4.7)
        None of your spec sources contain a spec satisfying the dependency: `Alamofire (~> 4.7)`.
















實際上用pod search也的確是找不到Alamofire 4.7版、PKHUD 5.0版,解決方式參考CocoaPods Guides - The PodfileFrom a podspec in the root of a library repo.
修正後的pod file為
        pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '4.7.0'
        pod 'PKHUD', :git => 'https://github.com/pkluz/PKHUD.git', :branch => 'release/swift4'
   

再pod install成功執行如下
    

'....failed to commit files' Couldn't communicate with a helper application.

如題,某天在Xcode commit files遇到此狀況,解決方式如下

●先確認你的git name & email是否跑掉(空值)
Show you the global settings for user.name and user.email (and other things)
git config --global -l
參考網址 https://forums.developer.apple.com/thread/18560

●如果真的跑掉,再設定回去吧
1.更改git電子郵件
指令    xcrun git config --global user.email xxxx
範例    xcrun git config --global user.email karen_chang@somedomain.com
2.更改git用戶名
指令    xcrun git config --global user.name xxxx
範例   xcrun git config --global user.name Karen_Chang

check in the Pods into source control ?

在Xcode搭配Git請參考這篇  將Xcode現有專案加入Git

如果專案有使用CocoaPods,.gitignore是否需要針對Pods處理呢?
答案是看你高興XD
只有Podfile 與 Podfile.lock一定要簽入版本控管,其他Pods就依照開發需求決定,簽入與否可參考CocoaPods的官方說明

Benefits of checking in the Pods directory
After cloning the repo, the project can immediately build and run, even without having CocoaPods installed on the machine. There is no need to run pod install, and no Internet connection is necessary.
The Pod artifacts (code/libraries) are always available, even if the source of a Pod (e.g. GitHub) were to go down.
The Pod artifacts are guaranteed to be identical to those in the original installation after cloning the repo.

Benefits of ignoring the Pods directory
The source control repo will be smaller and take up less space.
As long as the sources (e.g. GitHub) for all Pods are available, CocoaPods is generally able to recreate the same installation. (Technically there is no guarantee that running pod install will fetch and recreate identical artifacts when not using a commit SHA in the Podfile. This is especially true when using zip files in the Podfile.)
There won't be any conflicts to deal with when performing source control operations, such as merging branches with different Pod versions.
Whether or not you check in the Pods directory, the Podfile and Podfile.lock should always be kept under version control.

若上述優缺點還是無法協助你決定,可再參考stackoverflow的討論,看看哪種方式適合你~

參考資料
Should I check the Pods directory into source control?
What goes into your .gitignore if you're using CocoaPods?

將Xcode現有專案加入Git

在Xcode建立專案通常會問你要不要加入Git


如果你跟我一樣從沒加過,請繼續看下去XD

STEP 1 開啟Terminal終端機 & cd到準備作Git的Xcode Project
其中cd的路徑只要到 "專案名稱.xcodeproj" 這一層即可
若不熟Mac Terminal cd用法,請參考[MAC] 小技巧 – 快速將終端機開啟在指定路徑下
STEP 2 初始化git
輸入git init
強烈建議先跳到STEP 4 & 5處理gitignore,完成後再繼續做STEP 3

STEP 3 加入git
輸入git add .
按下Enter
輸入git commit -m 'initial commit'
讓他跑一下,會出現上圖落落長的資訊
此時,重新開啟Xcode會發現本來反灰無法使用的Source Control可以用了!打開History也有了剛剛第一次Commit的紀錄


STEP 4 處理gitignore
cd回去專案目錄
輸入vim .gitignore

按下Enter

輸入 i 進入編輯模式


STEP 5 取GitHub取得gitignore資訊
前往github/gitignore抓取適合你的gitingore檔案,我的專案是用Objective-C寫的,所以抓gitignore/Objective-C.gitignore就好
接續前一步驟的編輯模式,複製gitignore/Objective-C.gitignore所有內容並貼至Terminal

貼上所有內容

按下Esc鍵
接著輸入:wq 
按下Enter


以上,全部做完就可以成功將現有專案加入git控管
但要注意的是,這只是local git,remote git就看你採用哪一家的,主要是前面的都做成功後,接下來就都用Xcode的Source Control操作就好

參考資料