閱讀67 返回首頁    go windows


Xcode5中的版本管理(中英對照)

更多信息請移步:https://xiebaochun.github.io/

Beginning Source Control in Xcode 5

Xcode5中的版本管理

By Felipe Laso Marsetti

[Vicki will update the formatting for this section]

 

Source control is the practice of managing and tracking changes to files. The files can be anything from a Word document or PDF, to an Objective-C header or implementation file, but in this chapter we’re mainly going to focus on using source control to manage your Xcode projects.

版本控製是管理和記錄文件變更的實踐。這些文件可以是Word文檔,PDF,Objective-C頭文件或實現文件等任意格式,但在本章中我們關注的重點是使用版本管理工具管理你的Xcode項目。

Whether you’re an independent developer or part of a larger team, it’s very important to use source control in your apps. 

無論你是獨立開發者或者是大團隊中的一員,在你的App中使用版本管理都是非常重要的。

· If you’re working in a team, it’s almost a necessity to allow multiple people to work on the same codebase and not step on each other’s toes.

· 如果你在團隊中工作,使多人在同一個代碼庫下工作並且相互尊重,這幾乎是必須的。

· If you’re working on your own, source control is still extremely useful. It allows you to revert recent changes to code to get back to a good, known state, track diferent versions of your apps, and much more.

· 如果你是自己工作,版本管理仍然非常有用。它能讓最近的更新還原至一個良好的、已知的狀態,記錄應用的不同版本,等等。

Think of source control like Time Machine for your programming projects; it gives you the security to change your code without fear of breaking the main codeline, and the accountability of a change history so that you can figure out “what, who, and when” if things do happen to go wrong. 

版本管理就像編程項目的Time Machine;它保證了代碼變更的安全性而不用擔心破壞了主要的代碼片段,而且有變更曆史的說明,這樣在發生錯誤時你就能找出“誰在什麼時候做了什麼”。

Xcode has source control integration built right in (both in the user interface and command line), making it easy to use in your projects. The source control system Xcode uses is called Git, which is a free and open source distributed source control system that is easy to learn, lightweight and very fast.

Xcode集成了版本管理,可通過用戶界麵(user interface)和命令行創建,使版本管理在你的項目中簡單易用。Xcode使用的版本管理係統叫Git,這是一個免費開源的版本管理係統,易學、輕量級而且高效。

This chapter will give you a crash course on the Git source control system and guide you through the creation of a project that will be stored on GitHub, which is a repository host as well as a team collaboration tool.

本章將提供你一個Git版本管理係統的速成教程,通過創建一個將在GitHub上存儲的項目來指導你,GitHub是一個版本庫主機,同樣也是一個團隊協作工具。

If you’re already familiar with the basics of Git and have created and checked out a repository before, feel free to jump ahead to the next chapter, which deals with remote repositories and merging.

如果你已經熟悉Git的基礎知識,而且之前已經創建並檢查過倉庫,那麼你可以直接跳至下一章:遠程倉庫和合並處理。

Getting started

開始

The best way to learn about source control is to use it; it’s time for you to get your feet wet and actually use Xcode with Git.

學習版本管理最好的方法就是直接使用它。現在是時準備實戰Xcode中的Git了。

Open Xcode and create a new iOS Master-Detail Application named ControllingSource with your own Organization Name and Company Identifier, targeted for iPhone and that uses Core Data, as below:

打開Xcode並創建一個新的iOS Master-Detail Application,將其命名為ControllingSource,使用你自己的組織名字和公司標誌,目標設備為iPhone,使用Core Data,如下圖所示:

 

Click Next, but before you click anything else be sure to check the option at the bottom of the window called Create git repository:

點擊Next,在你點擊任何東西之前確保窗口底部的選項是選中的,此選項是Creat git repository:

 

Then choose a directory to save your project and click Create. Your project is now under git source control!

接著選擇一個文件夾來保存你的項目並點擊Create。現在你的項目就在git版本管理下!

To prove this for yourself, select any file in the project navigator, open the file inspector and scroll down until you see the Source Control section. There’s quite a bit of info in here, as shown by the following screenshot:

為了證明,你可以選擇 project navigatior中的任何文件,打開文件查看器並向下滾到Source Control的部分。如下截圖所示,有相當多的信息在裏麵:

 

Let’s go over each of the items in this pane:

讓我們看一下麵板中的每一項:

· Repository: the name of the Git repository, which defaults to the name of the project.

· Repository: Git倉庫的名稱,默認為項目名稱。

· Type: the type of the repository, which is Git. At the time of writing this chapter, Xcode supports both Git and Subversion source control systems, although Git tends to be more popular in the iOS development community.

· Type::倉庫類型,即Git。 雖然Git在iOS開發社區更為流行,但在寫本章時,Xcode支持Git和Subversion兩種版本管理係統。

· Current branch: The fundamental unit in Git is a commit. A commit consists of changes to one or more files, and is identified by a unique alphanumeric ID called a hash or SHA. A commit also records the timestamp and the name of the person who made the change.

· Current branch::Git的基本單元是一個提交(commit)。一個提交對象由一份或多份文件變更和一個用以識別的名為hash或SHA的唯一字母數字ID組成。提交對象還會記錄時間戳和執行變更的人名。

A branch is a pointer to a specific commit that represents a state of the repository. The default branch in Git when you create a new repository is called master, which is what you see here. You will learn more about branches in the next chapter.

分支是指向一個特定提交對象的指針,代表著該倉庫的一種狀態。當你創建一個新的倉庫時,Git中默認的分支叫做master,即你在這此處看到的。你將在一下章學習更多有關分支的知識。

· Version: You’re probably used to thinking of versions as sequential numbers, like version 1.0 of an app or version 10.9 of OS X. As previously mentioned, commits in Git are identified by a commit ID, a unique 40-character SHA1 hash that points to the exact state of your working directory when a commit is made. Here Xcode shows the first twelve characters of the commit’s hash, which are generally enough characters to be unique.

· Version:過去你可以認為版本就是一些有一定順序的數字,例如應用的1.0版本或者OS X的10.9版本。如之前提到過的,提交對象在Git中是通過一個提交ID和一個唯一的含有40字符的SHA1哈希碼標示的,這表示提交發生時你工作目錄的具體狀態。Xcode中顯示了提交對象哈希碼的開頭12個字符,通常這麼多字符已具備唯一性。

· Location: The location of the file on your drive.

· Location:文件在硬盤中的位置。

Git settings

Git設置

Before you continue working with git, you should configure git with your name and email address so that your changes are tracked properly. To do this, open a Terminal window and enter the following commands:

在你繼續使用git之前,你應該將你的用戶名和email地址設置到git中,這樣git才能正確地記錄你的變更。為此,打開終端窗口並輸入下麵的命令行:

git config --global user.name "YOUR NAME HERE"

git config --global user.email "EMAIL"

These commands will save your name and email to your local ~/.gitconfig file; these settings only apply to you, not any other accounts accounts on your computer.

這些命令行會將你的用戶名和email保存到你本地的~/.gitconfig文件中;這些設置僅應用於你,不包括你本機的其他賬號。

To verify your changes, type in the following command in Terminal:

為了驗證你的變更,在終端中輸入下麵的命令行:

git config –l

This will list all of the Git configuration options that are currently set. As you can see, there are many more settings you can configure and customize from Terminal; to learn more about them you can type the following command in Terminal:

該命令會列出當前設置的所有 Git配置選項。正如你所看到的,有很多設置你可以設定而且可以通過終端自定義;想要學習更多關於配置的內容可以在終端中輸入下麵的命令行:

git config –help

Adding Git to an existing project

在已存在的項目中添加Git

If you have an existing project that you’d like to place under source control there is no way to do so within Xcode. However, it’s easy to set things up manually. To see how this is done, follow the steps below to create a sample project without Git, and then add it after the fact.

如果你有一個已存在的項目,你想將它置於版本管理下,但是這在Xcode中是無法做到的。不過,手動設置非常簡單。為了演示做法,先根據下麵的步驟創建一個沒有Git的示例項目,接著再添加Git。

Create a new Xcode project called ExistingProject with the same settings as the ControllingSource project, but this time don’t click the check box for creating a Git repository. Select a file and verify it is not under source control in the File Inspector:

創建一個新的Xcode項目,名為ExistingProject,配置與ControllingSource項目相同,但是這次不要勾選創建Git倉庫的選框。在File Inspector中選擇一份文件並確保它不在版本管理下:

 

Now open the Terminal application, type cd with a space afterwards, then drag the project folder to the terminal window. You should see something similar to what’s shown in the screenshot below:

現在打開終端,輸入cd並空一格,接著將項目文件夾拖入終端窗口。你就會看到同下麵截圖所示的畫麵:

 

Hit Return on your keyboard, then type ls -la followed by another Return. This lists the items in the ExistingProject directory as illustrated below:

敲擊鍵盤上的Return,接著輸入ls –la再次點擊Return。如下方截圖所示,該命令會列出ExistingProject文件夾的所有的項:

 

If the project were under git source control you’d see a hidden directory named .git. Since there isn’t one, initialize a Git repository for this project by typing git init and hitting Return; Git will respond with the following:

如果該項目在git版本管理下,你會看到一個名為.git的隱藏目錄。由於目前沒有,所以輸入git init來初始化本項目的Git倉庫並點擊Return;Git會做出如下反饋信息:

 

If you see Initialized empty Git repository like you see here, that means the command was successful.

如果你看到如上圖中的Initialized empty Git repository,那意味著命令執行成功。

Type git status to see should get the current status of your working directory.

輸入git status,應該能看到工作目錄的當前狀態。

 

The output above shows that none of the files or folders in your project directory are being tracked by Git. There’s also a helpful message noting that you can use git add to specify what files and directories to include in the next commit.

上麵的輸出顯示了項目目錄中沒有文件或者文件夾被Git記錄。還有一個有用的消息,你可以使用git add來指定哪些文件或文件夾可以被包含在接下來的提交中。

However, note that the output shows a file called .DS_Store, which is a special hidden file created by OS X that contains attributes about a folder such as positions of icons within the folder. This is typically something you don’t want to track in source control, because it is specific to your particular machine and has nothing to do with the project itself.

然而,注意輸出中顯示了一份叫.DS_Store的文件,這是OS X創建的特定隱藏文件,它包含了一個文件夾的屬性,例如文件夾圖標的位置。這是你不想記錄在版本管理下的典型文件,因為這根據特定機器有特定的設置並且與項目本身沒有任何關係。

So before adding files for tracking and making your first commit, it would be wise to learn how to exclude certain files from your repository automatically. You can do this with a special file called .gitignore.

所以在添加記錄文件和做首次提交之前,學習如何讓倉庫自動排除特定文件是十分明智的。你可以使用一份名叫.gitignore的特定文件。

The .gitignore file

.gitignore文件

The .gitignore file contains rules that indicate which files not to track or show in the staging area. Git will check each filename against the list of rules in .gitignore, and ignore the file if there is a match.

.gitignore文件存在一些規則來表明哪些文件不該記錄或者顯示在暫存區。Git將會檢查每份文件名,保留不匹配.gitignore規則列表的文件,忽略匹配的文件。

Open any text editor and add the followings lines to a new file:

打開任意文本編輯器並添加如下行至一份新的文件:

# Xcode

.DS_Store

*/build/*

*.pbxuser

!default.pbxuser

*.mode1v3

!default.mode1v3

*.mode2v3

!default.mode2v3

*.perspectivev3

!default.perspectivev3

xcuserdata

profile

*.moved-aside

DerivedData

.idea/

*.hmap

This ignores many of the common types of files that you don’t typically want in your git repositories. This is a good starter default .gitignore; you may want to keep a local copy to reuse in future projects. 

上述文件能忽略許多你不太想加入git倉庫的相同類型文件。創建默認的.gitignore文件是一個好的開始;在未來的項目中你可能想要保存本地副本以備重建。

Note: The fine folks at GitHub maintain an extensive collection of gitignore files for many tools and languages that might come in handy. You can find them here:

注意: Github上維護了一個廣泛的gitignore文件集合,在許多工具或語言上可能會派上用場。你可以在這兒找到它們:

https://github.com/github/gitignore

Save the file in your ExistingProject project directory and name it .gitignore. 

Go back to the terminal window and type git status once again:

將文件保存到ExistingProject項目目錄並命名為.gitignore。回到終端窗口並再次輸入git status:

 

This time, there is no .DS_Store file as you specified it as one of the files to be ignored in .gitignore. It’s usually a good idea to track and commit .gitignore so other users of the repository can use the same settings and prevent them from committing unwanted files as well.

這次沒有.DS_Store文件,因為你在.gitignore文件中指定.DS_Store是需忽略的文件之一。記錄並提交.gitignore文件是個好的想法,這樣該倉庫的其他用戶也能使用相同的設置,從而防止他們提交了不想要的文件。

Note: This is a good starter default .gitignore; you may want to keep a local copy to reuse in future projects. The fine folks at GitHub maintain an extensive collection of gitignore files for many tools and languages.

注意:創建默認的.gitignore文件是一個良好的開始;在未來的項目中你可能想要保存本地副本以備重建。Github上維護了一個廣泛的gitignore文件集合,在 許多工具或語言上可能會派上用場。

A command line commit

提交命令

With your .gitignore ready, it’s time to stage your files and make your first commit. Enter this command in the terminal to add all the untracked files to the staging area:

.gitignore準備好後,是時候暫存你的文件並做初次提交。在終端中輸入該命令添加所有未記錄的文件至暫存區:

git add .

Now enter git status one more time and notice how everything in your project is in the staging area but not yet committed.

現在再次輸入git status,注意項目中的每份文件在暫存區並未提交時是怎樣的。

 

To commit your files, enter the following command:

提交文件需輸入如下命令:

git commit -m "Initial commit."

This tells Git to commit everything in the staging area (which, at the moment is everything in your project) along with the quoted message specified with the –m flag. 

這個命令告知Git將暫存區的文件全部提交(此時是項目中的全部文件),同時通過-m標記特定的補充說明信息。

Now enter git status to view the state of your repository. It should show that your repository HEAD is pointing to the default master branch, there’s nothing to commit, and that your working directory is clean, as below:

現在輸入git status來查看倉庫的狀態。輸出應該會顯示指向默認master分支的倉庫HEAD,沒有任何文件提交,你的工作目錄是空的,如下圖所示:

 

Quit Xcode 5 and re-open ExistingProject. Select any item in the project and open the File Inspector; you should see details similar to the following:

退出Xcode 5並重新打開ExistingProject。選擇項目中的任一項並打開File Inspector;你應該會看到如下圖的詳情:

 

Just as with your ControllingSource project, you now have an Xcode project with a Git repository initialized, a .gitignore file and the first commit.

如同ConrollingSource項目,現在你有一個帶已初始化Git倉庫的Xcode項目,一份.gitignore文件,而且做了初次提交。

Committing changes in Xcode 5

在Xcode5中提交變更

Now that you’ve learned how to put an existing project under source control and how to change your Git settings, it’s time to make some code changes in Xcode and learn how to commit them.

現在你已經學習了如何為已存在的項目添加版本管理和如何修改Git的設置。是時候在Xcode更改一些代碼來學習如何提交這些變更了。

Open the ControllingSource project and have a look at the project navigator. The files could stand to be organized a little better than they are currently. To start, group the view controllers together to make them easier to manage.

打開ControllingSource項目並看看project navigator。文件還可以組織地比現在更好一點。開始前,將視圖和控製器放在一組可以更方便管理。

Select the four view controller files in the project navigator and right-click to open the context menu. Select New Group From Selection to group the files together and  name the group View Controllers.

在project navigator中選擇4份視圖控製器文件,右鍵打開上下文菜單。選擇New Group From Selection,把這些文件集中到同一組,組名為View Controllers。

 

While you’re at it, group the layout resources into a group and name it Resources, as so:

當你編組的時候,把布局資源也集中到一組,命令為Resources,如下所示:

 

Note that the project file has an M next to it. This indicates that the project file, or something within the project, has been modified.

注意項目文件有一個M在名稱旁邊。這表明項目文件或者項目中的一些文件有了變更。

To commit the changes, right-click on the project file and select Source Control Commit, as shown below:

提交變更時,右鍵項目文件並選擇Source Control Commit,如下所示:

 

A drop-down window will appear with the list of files that have changed, the option to select what files to commit and a field for a commit message. Add a comment describing the reason for the commit, such as “Organize project navigator”, and click Commit.

接著會出現一個下拉窗口,裏麵有變更的文件列表、選擇哪些文件提交的選項和一個用於填寫提交信息的文本框。添加注釋表述這次提交的原因,例如“編組project navigator”,接著點擊Commit。

 

Now that you’ve committed some changes, how can you view what was changed? One way to view your commit logs is with the version editor. Click and hold on the version editor button and select Log, as shown below:

現在你已經提交了一些變更,如何能看到哪些變更了呢?其中一個方法是使用版本編輯器查看提交日誌。長按版本編輯器按鈕並選擇Log,如下圖所示:

 

In the version editor you can see the abbreviated commit hash, the name of the person who made the commit, the date, and the files modified in the commit, as so:

在版本編輯器中,你可以看到簡略的提交哈希碼、做該次提交的用戶名、時間以及這次提交中修改的文件,如圖:

 

The commit list on the right hand side shows a high-level view of the history of the file, and you can click on the “Show 1 modified file” text to see what was changed in each commit.

在右側提交信息列表,該列表顯示了曆史文件的高級視圖,你可以點擊“Show 1 modified file”文本來查看每次提交都有哪些變更。

Let’s try out the other two verion editor options. Click and hold the version editor button again, but this time select Comparison. You should see the following:

讓我們試試另外兩個版本編輯器選項。再次長按版本編輯器按鈕,不過這次選擇Comparison。你應該可以看到如下所示:

 

The Comparison view shows the current state of the file side-by-side with the last committed state; this can be useful to review your latest changes with the previous revision. 

Comparison視圖並排顯示了該文件當前狀態和最後一次提交狀態;這在你回顧上個版本的最近變更十分有用。

You can try the last version editor option if you’d like (Blame), but the blame view is unavailable for project files so it won’t show anything interesting. For other types of files, you will find it useful because it annotates lines and blocks of code with the relevant commit information, such as name, date, and message. This view is very helpful to see when certain portions of the code were changed, and more importantly, who to blame (or congratulate!) for those changes.

如果你想Blame,你可以嚐試版本編輯器的最後一個選項,但blame視圖對項目文件不可用,所以沒辦法展示任何有趣的東西。對其他類型的文件,你會發現它很有用,因為它顯示了代碼行和代碼塊的相關提交信息,例如用戶名、日期和補充信息。這個視圖對於看特定部分的代碼變更時間非常有幫助,更重要的是對那些變更哪些人該問責(或者鼓勵!)。

Viewing your project history

查看項目曆史

You’ve already seen how to review your commit logs with the version editor, which shows details on a file-by-file basis. You can also see the history of the project as a whole from the top-level repository view.

你已經了解了如何通過版本編輯器檢查你的提交日誌,版本編輯器是基於單個文件顯示詳情的。你也可以通過頂級倉庫視圖來查看整個項目的曆史。

From the main menu, select Source Control\History, as shown below:

回到主菜單,選擇Source Control\History,如下圖所示:

 

You’ll see a screen with all the commits made to your project, and similar to the version editor’s log view, the commit’s hash, contact information, date and changed files, as shown below:

你將看到屏幕中出現該項目的所有提交,類似版本編輯器的日誌視圖,有提交的哈希碼、用戶信息、時間和變更的文件,如下圖所示:

 

This view is particularly helpful if you want to get an overview of the changes to the project as a whole rather than on an per-file basis.

如果你想獲取整個項目的變更概況而不是單份文件,這個視圖就十分有用。

Adding the project to GitHub
添加項目到Github

Recall that Git is a distributed and decentralized system. That means all your commits are being made locally; if you delete the top-level project directory, the Git repository would disappear too. Your entire project is only an errant right-click away from impending doom! What to do?

記住,Git是一個分布式係統。就是說你的所有提交都是在本地進行的;如果你將頂級項目目錄刪除,那麼Git倉庫也會消失。你的整個工程就因一個右鍵操作的失誤而消失!怎麼辦?

Having a server component means you can easily share your code and collaborate with others. You can host a repository on your own server, or use a hosted service like GitHub. If you don’t have a GitHub account, head to github.com to get one. After signing up, you’ll need to configure a set of keys to be able to communicate with the repository via SSH.

擁有一個服務組件意味著你可以輕鬆地將你的代碼與合作案分享給其他人。你可以在你自己的服務器上存放一個倉庫,或者使用一個像GitHub這樣的主機服務。如果你沒有GitHub賬號,請到github.com申請一個。注冊完之後,你需要配置一係列密鑰,這樣可以通過SSH來和此倉庫進行交流。

SSH setup

SSH的配置

GitHub uses a pair of keys — one public and one private — in order to communicate securely with your computer. First, find out if you already have an SSH keypair by typing the following commands in a Terminal window:

為了在你的計算機上進行安全的溝通,Github使用一對密鑰(一個公開的和一個私有的)。首先,在中端窗口中輸入如下命令查看你是否已經有了一個SSH鍵值對。

cd ~/.ssh

ls

If you see a file named id_rsa.pub or id_dsa.pub then you’ve already generated your SSH keys. In that case skip straight to the section titled Adding your SSH key to GitHub.

如果你看到一個名為id_rsa.pub或者id_dsa.pub的文件,那麼說明你已經生成了你的SSH密鑰。如果是這樣的話,請直接跳至“添加你的SSH密鑰到GitHub”部分。

If you don’t see either of those files, or you get a “No such file or directory” error, then type the following command in Terminal to generate a pair of SSH keys:

如果你沒有看見任何文件,或者得到“No such file or diretory”錯誤,那麼在終端窗口中輸入如下命令獲取一對SSH密鑰。

ssh-keygen -t rsa -C "YOUR EMAIL"

You’ll then be prompted to enter a passphrase; this is optional but highly recommended to secure your keys. Once that’s done, your SSH keys are ready to be added to GitHub.

你將會被要求輸入一個密碼;這是可選的,但是為了你的密鑰的安全考慮,強烈建議輸入一個密碼。一旦完成之後,你的SSH密鑰就已經添加到了GitHub中。

Adding your SSH key to GitHub

If not already there, navigate to the .ssh directory in your home folder and open the id_rsa.pub file (or id_dsa.pub file if you have that one) in a text editor. Copy the contents of the file and go to your account settings on github.com. 

如果還沒完成的話,在你的主文件夾下找到.ssh目錄,並在文本編輯器中打開id_rsa.pub文件

Select the SSH Keys option then click the Add SSH key button, as below:

選擇SSH Keys選項,然後點擊Add SSH key按鈕,如下所示:

 

 

Paste the contents you copied from the .pub file into the Key section and give it a title, as shown below: 

將.pub文件複製的內容粘貼到Key部分並為其設置一個標題名,如下所示:

 

 

As far as a name goes, you can just use the name of the computer this key corresponds to  — although note that you can reuse the same key on multiple computers.

如果你覺得名字很難取的話,你可以使用這個密鑰對應的計算機名,你也可以在多台計算機上使用重複使用相同的密鑰。

Creating a new repository on GitHub

在GitHub上創建一個新倉庫

With your keys set up you can now create a new repository and push your project to GitHub.

設置好密鑰之後,你就可以創建一個新倉庫並且可以將你的工程推送到Github上。

On the GitHub home page, click on the New Repository button to create a new repository, as shown below:

在GitHub首頁,點擊New Repository按鈕創建一個新倉庫,如下所示:

 

You’ll be taken to a page where you can input some info for your repository.

你將會進入一個頁麵,你可以在此處輸入一些關於倉庫的信息。

The owner should default to your account; note that you can belong to more than one GitHub team. For the repository name type ControllingSource, give it a description, and make it a public repository; private repositories require a paid GitHub account. Ensure the options to initialize the repository with a readme, gitignore or license file remain unselected as shown below:

倉庫所屬者默認是你的賬戶名;注意你可以同時屬於多個GitHub團隊。給倉庫的名字取ControllingSource,給它一個說明,並將其設置為公共倉庫;私有倉庫需要一個認證GitHub賬戶。確保initialize the repository with a readme, gitignore 或者 license file 這幾個選框未選中,如下所示:

 

Finally, click the Create repository button; you’ll see a screen with some instructions on how to create a new repository or take an existing repository and push it to GitHub.

最後,點擊Create repository按鈕;你將會進入一個說明頁麵,裏麵介紹了怎樣去創建一個新倉庫,或者將一個已存在的倉庫推送到GitHub中。

Rather than spend more time on the command line, you’ll be using Xcode 5 to add the GitHub repository as a remote and push to it.

你將會使用Xcode 5來添加一個GitHub倉庫作為一個remote(遠程連接)並將倉庫推送到那裏,而不是花很多時間在命令行中完成此操作。

The only thing you need to do is to copy the SSH address from GitHub for use in a moment:

你隻需要從GitHub上複製SSH地址就行了。

 

Pushing the changes to GitHub

將更改推送至GitHub

Go back to Xcode and click the Source Control menu item. Select the master branch and choose the Configure ControllingSource option, as below:

回到Xcode並點擊Source Control菜單項,選擇master分支,並選擇Configure ControllingSource選項,如下所示:

 

Click the “Remotes” tab and then the “+” button, as so:

點擊“Remotes”欄,然後點擊“+”按鈕,如下所示:

 

Type ControllingSource for the remote repository name, paste the SSH address you copied from your GitHub repository, and click Add Remote, as shown below:

輸入ControllingSource作為遠程倉庫的名字,將剛剛從GitHub倉庫中複製的SSH地址粘貼到這裏,並且點擊Add Remote按鈕,如下所示:

 

Back in the configuration window, click Done and select the Source Control menu item again; this time select the Push option:

回到配置窗口,點擊Done並在再次選擇Source Control菜單項;這次選擇Push選項。

 

 

In the popup, you should see a dropdown titled “Push local changes:” along with a selection of branches to push to GitHub. Select the only branch available — master — and click Push, as below:

在彈出的窗口中,你應該可以看到一個標題為“Push local cahnges”的下拉框,裏麵表示的是將要推送到GitHub上的一個分支。選擇唯一一個可用的分支(master),並點擊Push按鈕,如下所示:

 

Go to your repository on github.com and refresh the page to see the results. The resulting table shows the branch you committed to, the number of commits, all of the files in the project as well as all of the contributors to the project:

在github.com中進入你的倉庫並刷新此頁麵查看結果。在結果欄中顯示了你已經提交的分支,一些提交信息,工程裏的所有文件,還有對此工程的所有貢獻者。

 

 

00001That’s the end of the line — you’ve pushed your repository to GitHub and it’s now stored safely on the server.

所有的流程已經完成了(你已經將倉庫推送至GitHub並且現在已經安全地保存在這個服務器中)。

From here on out, if you want to make changes you can follow these same two steps:

至此,如果你想對倉庫進行更改,你可以通過下麵兩個步驟來完成:

1. Go to Source Control\Commit to commit your changes locally.

2. Go to Source Control\Push to push your changes to Github.

1.選擇Source Control\Commit來提交本地更改。

2.選擇Source Control\Push將你的更改推送至GitHub.

Challenges

挑戰

Source control is a practice that every developer should follow. Regardless of how many people are involved or what type of projects you work on, source control is a huge time-saver — and even sometimes a lifesaver! 

版本管理是一個實踐,每位開發者都應該掌握。不管有多少人參與其中或者你工作在什麼類型的項目裏,版本管理是一個省時省力的工具(有時甚至是一個救命稻草!)

Apple is making a strong push in Xcode 5 to encourage the use of source control, just as they are with unit testing and continuous integration. There are a lot of enhancements and new features with source control in Xcode 5, many of which you have seen in this chapter.

蘋果在Xcode5中正在不斷增強推送功能來鼓勵版本管理的使用,如單元測試和進一步整合。在Xcode 5中有許多增強元素和新的功能,你已經在本章中學到了其中的許多內容。

So far, you’ve only learned the basics of working with source control. In the next chapter, you’ll work with an app on a remote repository and learn about working with multiple branches, merging and more.

目前,你隻是學習了版本控製的基本工作原理。在接下來的一章中,你將會在一個遠程的倉庫中處理一個應用,並學習多分支,合並等更多相關知識。

But first, it’s time for you to try a quick challenge to make sure you understand what you’ve learned so far.

但是,現在你將要做的是嚐試解決一個即時挑戰,確保你已經掌握了目前學到的知識。

Challenge 1: Your own commit

挑戰1:你自己的提交

00002This is a quick and simple challenge that mimics what you’ll do most frequently while developing. You’ll make a change, commit and push the, and verify the change is visible on GitHub.

00003這是一個快速而簡單的挑戰,它模擬的是在開發中會頻繁用到的一個操作。你講需要做一個更改,並將其提交、推送,並且在GitHub上可以看到此變更。

1. Open Main.storyboard and modify the color of the prototype cell’s label and background in addition to the label and background color of the detail view controller.

1.打開Main.storyboard,並修改標簽單元和標簽背景的顏色,還有詳細視圖控製器的背景顏色。

2. Commit your changes from within Xcode and give the commit and appropriate message.

2.Xcode裏提交你的更改並給提交一個恰當的信息。

3. Push your changes to Github and verify that your commit is visible from your repository’s website.

3.將你的更改推動至GitHub,並確保在你的倉庫網站上能看到此變更。

If you get stuck please refer to previous sections of the chapter where you are shown how to commit and push changes in your repository. Feel free to use the sample project as a starting point for the challenge.

如果你遇到了困難,請參考本章之前關於如何提交並推送變更到你的倉庫的部分。你也可以使用同一個工程作為起點來完成此挑戰。

 

 

最後更新:2017-04-03 12:53:59

  上一篇:go mysql修改root密碼、登錄、導入導出等命令小記
  下一篇:go 檢查一個二叉樹是否平衡的算法分析與C++實現