天天看點

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

using git in xcode

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

<a href="http://www.cimgf.com/2013/12/10/using-git-in-xcode/" target="_blank">http://www.cimgf.com/2013/12/10/using-git-in-xcode/</a>

git has become a very popular version control system in ios and mac development. git comes with a set of command line tools to check status, commit changes, view logs, make and merge branches, and coordinate commits with a remote repository.  there are a number of desktop apps that can perform these functions, including xcode.  when i ask other ios and mac developers how they interact with git, most say they use the command line or a separate desktop app like tower.  i find very few developers use xcode for even some basic git tasks, and many developers are not aware of the git support xcode offers.

git已經成為了非常流行的版本控制工具。git是一系列的指令行工具,用以檢查狀态、送出更改、檢視日志、建立和對比分支、并将源碼遠端送出到伺服器上。有很多很多工具都能做這項事情,xcode自身也有git的功能。我問了很多ios以及mac的開發者他們是怎麼使用git的,大部分都說他們使用指令行工具,或者是一個獨立的app例如tower。我發現很少有人使用xcode自帶的git來進行最基本的一些操作,還有,很多開發者根本就不知道xcode自身就支援git,提供了git的相關服務。

for my own workflow, i like to minimize the number of tools used and number of switches between apps needed to complete a task.  so, i decided to attempt to use xcode exclusively to interact with git and share my results.  so far i have been pleasantly surprised at what all xcode can do with git. if you have not taken a look at xcode’s support for git, you may be surprised how much you can accomplish.

在我的大部分工程當中,我喜歡用最少的工具來控制不同版本的app。是以,我決定嘗試一下使用xcode自帶的git以及分享我的經驗。至今為止,我發現xcode可以用git做到很多相當不錯的功能。如果你還沒有用過xcode自帶的git,當你在使用它的時候也許會被驚豔到。

this article assumes basic familiarity with xcode and git, and describes git functionality present in xcode version 4.6.2.

這篇文章假定你熟悉xcode以及git的使用,文章中的git的功能描述是在xcode的4.6.2版本上進行的。

new git project setup in xcode

since git is a distributed version control system, a repository can be created locally when starting a project, or on a remote server and then cloned.  xcode can handle both situations.

when creating a new xcode project, you can include a local git repository by checking the “create local git repository for this project” option.  xcode will initialize the repository and perform an initial commit with the template files for you.

自從釋出了git這個版本控制工具之後,一個工程拷貝既可以在本地建立,也可以通過從伺服器的拷貝來完成。xcode能處理這兩種情形。

當在建立一個新的xcode工程項目時,你可以在選項 create local git repository for this project 來包含一個本地的git拷貝。xcode會初始化這個拷貝并擷取到檔案供你使用。

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

if you are sharing your project with a team or just want a backup of your project on another machine, you can set up a remote copy of the repository.  the typical way this is done is to create an empty repository on a git service like github or bitbucket.  once the repository is available, return to xcode and open the organizer. select repositories to view all the version control repositories that xcode is aware of, and find the new project repository.  select remotes for the new project, add then click the add remote button.

如果你是團隊開發,或者僅僅隻想在另外的一台電腦上擷取一個拷貝,你可以建立一個遠端的拷貝。常用的方式是在github或者bitbucket上建立一個空的拷貝。一旦這個拷貝可以被你使用了,回到xcode後打開organizer。選擇 repositories 後可以檢視所有你可以操作的版本,然後找到建立新版本那一項,然後點選 add remote 按鈕添加。

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

xcode will present a dialog to add the remote. you can follow the default naming standard for a git remote and give it the name “origin”, or you use a custom name.  then specify the remote url for the repository, which will be provided by bitbucket.

xcode會顯示一個提示框來添加遠端版本,你可以根據預設值給個名字抑或自己起個名字。然後,你提供一個遠端版本的url位址,這個位址是由遠端伺服器提供的(比如github或者bitbucket)。

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

if the remote repository is private and requires authentication, you can enter it after the remote is added.  select the remote in the organizer list, and an authentication interface will appear below the list.

如果這個遠端的版本是私有的需要你提供驗證資訊,你可以在添加完了之後輸入驗證資訊。你在organizer選擇這個遠端版本,一個提示框會提示你輸入資訊的。

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

once the remote is added and authentication provided, the master branch needs to be pushed to it.  return to the xcode project window.  from the xcode menu, select file | source code | push… xcode will present a sheet which will allow you to select a remote to push to, and a branch to push.  note that xcode has checked with the remote repository, and indicates that the master branch will be created in the remote repository with the push.

一旦遠端的版本被添加了,你也輸入了驗證資訊,你就需要選擇要push的主分支了。回到xcode工程當中,在xcode菜單中,選擇 file | source code | push… xcode 後會出現提示框,讓你選擇一個版本來作為你push所用。

[翻譯] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

once the push is complete, the remote repository is available for updates and for other users.

一旦push操作成功了,你就可以使用這個遠端版本用來送出代碼了。

繼續閱讀