更多信息请移步:http://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的基础知识,而且之前已经创建并检查过仓库,那么你可以直接跳至下一章:远程仓库和合并处理。
开始
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:文件在硬盘中的位置。
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
在已存在的项目中添加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的特定文件。
.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文件集合,在 许多工具或语言上可能会派上用场。
提交命令
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文件,而且做了初次提交。
在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视图对项目文件不可用,所以没办法展示任何有趣的东西。对其他类型的文件,你会发现它很有用,因为它显示了代码行和代码块的相关提交信息,例如用户名、日期和补充信息。这个视图对于看特定部分的代码变更时间非常有帮助,更重要的是对那些变更哪些人该问责(或者鼓励!)。
查看项目历史
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.
如果你想获取整个项目的变更概况而不是单份文件,这个视图就十分有用。
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的配置
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中。
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.
如果你觉得名字很难取的话,你可以使用这个密钥对应的计算机名,你也可以在多台计算机上使用重复使用相同的密钥。
在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地址就行了。
将更改推送至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.
挑战
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.
但是,现在你将要做的是尝试解决一个即时挑战,确保你已经掌握了目前学到的知识。
挑战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.
如果你遇到了困难,请参考本章之前关于如何提交并推送变更到你的仓库的部分。你也可以使用同一个工程作为起点来完成此挑战。