接下来进行Try Git(http://try.github.io/)这个网站后续的命令讲解。
1.14Staged Differences
Another great use fordiffis looking at changes within files that have already been staged. Remember, staged files are files we have told git that are ready to be committed.
Let's usegit addto stageoctofamily/octodog.txt, which I just added to the family for you.
git add octofamily/octodog.txt
1.14阶段性差异。
diff的另一个很棒的用法就是查看已经在文件中的更改,记住,阶段文件是你告诉git已经准备好提交的文件
使用git add来保存阶段性文件octofamily/octodog.txt,。这是文件是我刚刚为你添加进家庭的文件。
1.15Staged Differences (cont'd)
Good, now go ahead and rungit diffwith the--stagedoption to see the changes you just staged. You should see thatoctodog.txtwas created.
git diff --staged
1.15阶段性差异(续)
现在你可以继续运行git diff(加上参数---staged)来查看你上个命令产生的变化。
你可以看到octodog.txt这个文件已经被创立了
1.16Resetting the Stage
So now that octodog is part of the family, octocat is all depressed. Since we love octocat more than octodog, we'll turn his frown around by removingoctodog.txt.
You can unstage files by using thegit resetcommand. Go ahead and removeoctofamily/octodog.txt.
git reset octofamily/octodog.txt
1.16重新建立阶段性
所以现在octodog文件是family(目录)下的一部分了,octocat文件很郁闷,从你喜欢octocat文件大于octodog开始。我们可以移除octodog文件。
你可以使用git reset命令来删除文件。执行下面命令来移除octodog文件。
1.17Undo
git resetdid a great job of unstaging octodog.txt, but you'll notice that he's still there. He's just not staged anymore. It would be great if we could go back to how things were before octodog came around and ruined the party.
Files can be changed back to how they were at the last commit by using the command:git checkout -- . Go ahead and get rid of all the changes since the last commit foroctocat.txt
git checkout -- octocat.txt
1.17撤销
git reset做了一个伟大的工作,unstageing octodog文档。但你会注意到文档依然存在。只是不再stage了。如果你可以回退到在octodog文档创建之前的状态就好了。(原文用了比喻手法)
你可以使用git checkout -- .命令,从而是文档回退到最近一次的提交状态。自从上次提交octocat.txt文档之后带来的一系列变化,可以通过执行下面的命令来消除。从而回到到提交octocat.txt之前的状态
1.18Branching Out
When developers are working on a feature or bug they'll often create a copy (aka.branch) of their code they can make separate commits to. Then when they're done they can merge this branch back into their mainmasterbranch.
We want to remove all these pesky octocats, so let's create a branch calledclean_up, where we'll do all the work:
git branch clean_up
1.18分支清除
当开发者致力于开发一个特性或者修复bug时,他们经常先为他们的代码创建一个副本(也就是分支),在这个分支上可以进行单独提交。当工作完成时,他们可以将这个分支的代码合入到主分支(master)上。
当你希望清除掉这些烦恼的octocats时,你可以创建一个分支叫做clean_up,在这个分支上你可以执行所有的操作:
1.19Switching Branches
Great! Now if you typegit branchyou'll see two local branches: a main branch namedmasterand your new branch namedclean_up.
You can switch branches using thegit checkout command. Try it now to switch to theclean_upbranch:
git checkout clean_up
1.19切换分支
太棒了,现在你可以使用git branch来看到本地的两个分支,一个主分支master,和一个你的新建分支clean_up。
你可以使用git checkout 命令来选择使用哪个分支。下面是选择clean_up分支的命令:
1.20Removing All The Things
Ok, so you're in theclean_upbranch. You can finally remove all those pesky octocats by using thegit rmcommand which will not only remove the actual files from disk, but will also stage the removal of the files for us.
You're going to want to use a wildcard again to get all the octocats in one sweep, go ahead and run:
git rm '*.txt'
1.20移除所有文件
好了,你现在在clean_up分支当中了,通过使用git rm命令,你可以移除哪些烦恼的octocat文件了,这个命令不仅仅会从磁盘上移除最近的文件,同时也会将库上的文件同时移除。
你可以使用通配符,这样可以一次扫描就得到所有的octocat文件。继续执行:
1.21Commiting Branch Changes
Now that you've removed all the cats you'll need to commit your changes.
Feel free to rungit statusto check the changes you're about to commit.
git commit -m "Remove all the cats"
1.21提交分支的改变
现在你已经移除了所有的cat文件,你需要提交你所做的改变
运行gitstatus来查看你在你提交前后,库的变化。即检查即将提交的更改。
1.22Switching Back to master
Great, you're almost finished with the cat... er the bug fix, you just need to switch back to themasterbranch so you can copy (ormerge) your changes from theclean_upbranch back into themasterbranch.
Go ahead and checkout themasterbranch:
git checkout master
1.22切换回主目录
现在你已经删除了所有的cat,就当做是进行了bug的修复。你需要切换到master目录,这样你可以将你在clean_up分支上的改动合入到master分支上。
执行下面命令来检查主分支。
1.23Preparing to Merge
Alrighty, the moment has come when you have to merge your changes from theclean_upbranch into themasterbranch. Take a deep breath, it's not that scary.
We're already on themasterbranch, so we just need to tell Git to merge theclean_upbranch into it:
git merge clean_up
1.23准备合入
现在的情况是:你必须要将你clean_up分支上的改动合入到你的主分支上面去。深呼吸,这并不可怕。
我们已经在master分支下,所以我们只需要告诉git去合入clean_up分支就可以了,执行下面的命令:
1.24Keeping Things Clean
Congratulations! You just accomplished your first successful bugfix and merge. All that's left to do is clean up after yourself. Since you're done with theclean_upbranch you don't need it anymore.
You can usegit branch -d to delete a branch. Go ahead and delete theclean_upbranch now:
git branch -d clean_up
1.24保证库的干净。
恭喜!你已经成功完成了你的第一次bug修复并且合入。接下来要做的就是清除工作了,你完成了工作,你就不再需要clean_up这个分支了。
你可以使用git branch -d 命令来删除分支。现在执行下面命令,删除clean_up分支吧
1.25The Final Push
Here we are, at the last step. I'm proud that you've made it this far, and it's been great learning Git with you. All that's left for you to do now is to push everything you've been working on to your remote repository, and you're done!
git push
1.25最后的上库
现在已经到了最后一步了,我很自豪你做到了这步,和你一起学习git真是太棒了。
你接下来要做事情只有一个:将你到目前为止所有的工作push到你的远程库上。这样你就大功告成了。
总结:
通过这个网站的学习,你可以初步了解到git的操作,说实话,git其实并没有想象中的那么高深。多多练习,熟悉常用的操作,很快你就会掌握git的各种用法了。