iOS開發那些事-Git在Xcode中的配置與使用

來源:互聯網
上載者:User

很多Git命令都是在命令列下啟動並執行,命令列下管理Git有很多優點不用多說。但最大的缺點是要求使用者記住這些命令。因此Git圖形介面還是很受一些使用者歡迎的,其中Xcode作為整合式開發環境工具,也提供了一定Git圖形介面功能。但是要想在Xcode中使用Git管理工程代碼還想需要進行一些配置,然後才能使用。 如果我們是使用Xcode 4建立的一個iOS工程,在終端的命令列中提交代碼時候,可能會出現下面的部分資訊: [cpp] create mode 100644 HelloWorld/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata    create mode 100644 HelloWorld/HelloWorld.xcodeproj/project.xcworkspace/xcuserdata/tonyguan.xcuserdatad/UserInterfaceState.xcuserstate    create mode 100644 HelloWorld/HelloWorld.xcodeproj/xcuserdata/tonyguan.xcuserdatad/xcschemes/HelloWorld.xcscheme    create mode 100644 HelloWorld/HelloWorld.xcodeproj/xcuserdata/tonyguan.xcuserdatad/xcschemes/xcschememanagement.plist    rewrite HelloWorld.xcodeproj/project.xcworkspace/xcuserdata/tonyguan.xcuserdatad/UserInterfaceState.xcuserstate (83%)   create mode 100644 HelloWorld/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 HelloWorld/HelloWorld.xcodeproj/project.xcworkspace/xcuserdata/tonyguan.xcuserdatad/UserInterfaceState.xcuserstate create mode 100644 HelloWorld/HelloWorld.xcodeproj/xcuserdata/tonyguan.xcuserdatad/xcschemes/HelloWorld.xcscheme create mode 100644 HelloWorld/HelloWorld.xcodeproj/xcuserdata/tonyguan.xcuserdatad/xcschemes/xcschememanagement.plist rewrite HelloWorld.xcodeproj/project.xcworkspace/xcuserdata/tonyguan.xcuserdatad/UserInterfaceState.xcuserstate (83%)  事實上是能夠列入到代碼版本控制的檔案是有規定的,不能是編寫的二進位檔案、臨時檔案和使用者特有的檔案等。下面是Xcode 4建立的HelloWorld工程的目錄結果: HelloWorld [cpp] ├── HelloWorld    │   ├── AppDelegate.h    │   ├── AppDelegate.m    │   ├── HelloWorld-Info.plist    │   ├── HelloWorld-Prefix.pch    │   ├── ViewController.h    │   ├── ViewController.m    │   ├── en.lproj    │   │   ├── InfoPlist.strings    │   │   └── ViewController.xib    │   └── main.m    └── HelloWorld.xcodeproj    ├── project.pbxproj    ├── project.xcworkspace    │   ├── contents.xcworkspacedata    │   └── xcuserdata    │       └── tonyguan.xcuserdatad    │           └── UserInterfaceState.xcuserstate    └── xcuserdata    └── tonyguan.xcuserdatad    ├── xcdebugger    │   └── Breakpoints.xcbkptlist    └── xcschemes    ├── HelloWorld.xcscheme    └── xcschememanagement.plist   ├── HelloWorld │   ├── AppDelegate.h │   ├── AppDelegate.m │   ├── HelloWorld-Info.plist │   ├── HelloWorld-Prefix.pch │   ├── ViewController.h │   ├── ViewController.m │   ├── en.lproj │   │   ├── InfoPlist.strings │   │   └── ViewController.xib │   └── main.m └── HelloWorld.xcodeproj ├── project.pbxproj ├── project.xcworkspace │   ├── contents.xcworkspacedata │   └── xcuserdata │       └── tonyguan.xcuserdatad │           └── UserInterfaceState.xcuserstate └── xcuserdata └── tonyguan.xcuserdatad ├── xcdebugger │   └── Breakpoints.xcbkptlist └── xcschemes ├── HelloWorld.xcscheme └── xcschememanagement.plist  其中HelloWorld.xcodeproj屬於包檔案,它內部的很多東西是不能提交的,包括:project.xcworkspace和xcuserdata,它們是與使用者有關的。Git中有一個.gitignore設定檔,在這個檔案中可以設定被忽略的檔案。下面的內容是一個.gitignore設定檔: [cpp] # Exclude the build directory     build/*    # Exclude temp nibs and swap files     *~.nib    *.swp    # Exclude OS X folder attributes     .DS_Store    # Exclude user-specific XCode 3 and 4 files     *.mode1    *.mode1v3    *.mode2v3    *.perspective    *.perspectivev3    *.pbxuser    *.xcworkspace    xcuserdata   # Exclude the build directory build/* # Exclude temp nibs and swap files *~.nib *.swp # Exclude OS X folder attributes .DS_Store # Exclude user-specific XCode 3 and 4 files *.mode1 *.mode1v3 *.mode2v3 *.perspective *.perspectivev3 *.pbxuser *.xcworkspace xcuserdata  檔案中#號是注釋,可以使用Regex,檔案考慮到了X code 3和4差別。這個檔案建立之後,應該放在什麼地方?如果只考慮對一個特定工程忽略,.gitignore檔案應該放在程式碼程式庫目錄下面,目錄結構如下所示: <程式碼程式庫目錄> [cpp]└── HelloWorld    ├── HelloWorld    │   ├── AppDelegate.h    │   ├── AppDelegate.m    │   ├── Default-568h@2x.png    │   ├── Default.png    │   ├── Default@2x.png    │   ├── ViewController.h    │   ├── ViewController.m    │   ├── HelloWorld-Info.plist    │   ├── HelloWorld-Prefix.pch    │   ├── en.lproj    │   │   ├── InfoPlist.strings    │   │   └── MainStoryboard.storyboard    │   └── main.m    └── HelloWorld.xcodeproj    │    └── .gitignore   └── HelloWorld ├── HelloWorld │   ├── AppDelegate.h │   ├── AppDelegate.m │   ├── Default-568h@2x.png │   ├── Default.png │   ├── Default@2x.png │   ├── ViewController.h │   ├── ViewController.m │   ├── HelloWorld-Info.plist │   ├── HelloWorld-Prefix.pch │   ├── en.lproj │   │   ├── InfoPlist.strings │   │   └── MainStoryboard.storyboard │   └── main.m └── HelloWorld.xcodeproj │ └── .gitignore  如果考慮適用於所有的Xcode工程,則需要使用git config命令配置git,在終端中執行git config命令: $ git config –global core.excludesfile  ~/.gitignore 該命令會將配置資訊寫入到~/.gitconfig檔案中,–global參數是配置全域資訊,~/.gitignore說明檔案是放置於目前使用者目錄下。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.