天天看點

[IOS]如何結合XCODE使用git以及異常處理

1.控制台cd到項目目錄下,輸入指令:git init

2.在git server建立xxx/project_name.git,輸入指令:git --bare init

3.本地控制台:

git add .
git commit -m "first Commit"
git remote add origin [email protected]:tingkongwanli/git.git
git push -u origin master      

4.這樣就建立成功了,可以在xcode添加git,然後checkout下來(第一次),以後有更新從master pull下來最新代碼

5.new a branch,然後可以寫你自己部分的代碼了。寫完後可以commit(local)

 注釋:merge from branch----從其他地方合并到我的branch

            merge into branch----把我的代碼合并到其他branch

6.push:用于最終發送到server。切換回master,merge from branch,把最新修改的branch代碼合并到master上,最後push上server上面

參考:http://www.jianshu.com/p/103d74b69a13

注意出現Git ignore UserInterfaceState.xcuserstate問題:

1.建立.gitignore,作用是讓git忽略自定義規則;

2.項目目錄下,建立.gitignore

touch .gitignore
open .gitignore      

3..gitignore中輸入

*.xcuserstate  
project.xcworkspace  
xcuserdata  
UserInterfaceState.xcuserstate  
project.xcworkspace/  
xcuserdata/  
UserInterface.xcuserstate 
.DS_Store      

4.在指令行輸入:

$ git rm --cached path/to/.DS_Store
$ git rm --cached *.xcuserstate

送出:
$ git add .gitignore
$ git commit -m "Remove and ignore .xcuserstate and .DS_Store files."      

這時候在xcode進行merger,會提示commit:

控制台輸入指令:

git rm --cached ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"