USING GIT IN XCODE
KEEPING IN SYNC WITH REMOTE REPOSITORIES
As you make changes in your local working copy you will want to keep them in sync with the remote repository. Xcode offers support for pulling from and pushing to a remote repository, and for tracking remote branches.
There are two ways to pull from a remote repository. The first is from the project window. Select File | Source Control | Pull from the Xcode menu when viewing a project window. If there are no uncommitted changes in the working copy, Xcode will present a dialog to select which remote and branch to pull from. (Note that a pull can be completed using command line Git when changes are present, but Xcode will not pull with uncommitted changes in the working directory.)
也許你想在本地備份上修改程式碼的時候,同步到伺服器端當中。Xcode提供了pulling一級pushing操作,以及追蹤遠端版本。
有兩種方式來從伺服器端pull程式碼。第一種方式就是直接在工程的window選單中操作。選擇File | Source Control | Pull from the Xcode menu,如果本地沒有進行修改的操作,Xcode將會提供一個選單供你選擇從哪一個分支上pull程式碼。
Alternatively, the Pull button from the Organizer Repositories view can be used when a working copy is selected.
另外一種方法是,這個Pull的按鈕可以從Organizer Repositories中點選。
If a conflict is detected on the pull, Xcode will present the merge viewer to resolve the conflict. Just like resolving a conflict between branches, the merge viewer can be used to select which change(s) should be kept and in what order they should be if both are desired. If you do not want to resolve the conflict, click the Cancel button in the merge view and the pull will not take place.
如果在pull過程中檢測到了衝突,Xcode會顯示出merge工具來幫你解決衝突。如果不想解決衝突,點選取消按鈕也行。
If the conflict is resolved, the working copy will be modified and will need to be committed and pushed.
To push changes to the remote repository, select File | Source Control | Push from the Xcode menu when viewing a project window.
如果衝突被解決了,你又寫了程式碼並想提交程式碼。
你可以通過File | Source Control | Push from the Xcode menu來提交程式碼。
A branch can also be pushed to the remote repository. Xcode will detect if the branch does not yet exist in the remote, and will indicate if the branch will be created by a push.
當然你也可以提交程式碼到一個新的分支中去,Xcode會檢測有沒有你想要的那個分支,如果沒有,他會幫你建立那個分支。
Once a branch has been created on the remote repository, other working copies can track that branch. To track a branch, visit Organizer, Repositories, and select Remotes for the project repository. Expand the remote name to see the available branches. (In my testing, I was not able to get Xcode to refresh remote branches without restarting Xcode).
一旦一個分支在伺服器上被建立了,其他的版本都能夠跟蹤那個分支。要跟蹤一個分支,訪問Organizer,Repositories,選擇Remotes for the project repository,然後選擇展開的那個分支的名字。
Select a remote branch and click the Track Branch button at the bottom of the view. This will pull down the branch from the remote repository to the local repository, will allow you to switch to the branch in Xcode, and will allow pulls and pushes to take place from it.
選擇了那個分支後點選Track Branch按鈕,你就會從伺服器更新到那個分支的程式碼,你可以隨意的在不同的分支中切換來切換去。
SUMMARY
As we have seen here, Xcode has very usable support for common Git tasks, including setting up Git for a new project, cloning an existing project, handling modifications and commits, viewing history, using branches, and pushing and pulling from remote repositories. Xcode does not have direct support for stashing, tags, or more advanced topics like rebasing or submodules. However, all of the items that Xcode does not support can be performed using the command line tools or using a third party tool. In my day to day work with a distributed development team, I am frequently able to perform all of my Git tasks in Xcode, and only rarely need to resort to the command line. Take a second look at Xcode’s Git support if you have not done so before, and give feedback to the Xcode team so they can keep enhancing and improving Git support in Xcode.
在這裡,我們可以看出,Xcode支援Git很到位,包括建立一個Git專案、拷貝一個Git專案,操作修改,提交程式碼,瀏覽歷史記錄,使用版本分支以及從伺服器進行push或者pull操作。Xcode並沒有直接支援諸如隱藏、標記、或者一些更高階更熱門的功能。然而,那些更高階的功能都能夠通過命令列工具或者是第三方工具來實現。在我日復一日的分散式團隊工作當中,我頻繁的使用者Xcode自帶的git工具,只有極少數情況會用到命令列。如果您沒用過Xcode自帶的git工具,你可以試驗一把,並給Xcode團隊反饋使用上不方便的地方,幫助Xcode提升Git的使用便利性^_^。