try git 在线教程part2

接下来进行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的各种用法了。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,295评论 6 512
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,928评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,682评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,209评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,237评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,965评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,586评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,487评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,016评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,136评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,271评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,948评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,619评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,139评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,252评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,598评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,267评论 2 358

推荐阅读更多精彩内容