学习 git,从此不再枯燥无味

最近在玩一个叫 “githug” 的游戏,看到这个名字,也许你马上就联想到了 git。是的,这是一个跟 git 相关的游戏,它把平常可能遇到的一些场景都实例化,变成一个一个的关卡,通过通关的形式,让你快速的学习 Git 并发挥其最大的威力。

Github 地址在这里:《GitHug》

下面介绍下怎么安装这个游戏。

安装

因为 githug 是用 Ruby 编写的,所以我们可以通过 gem 来安装,安装命令如下:

$ gem install githug

如果安装失败,就试试下面的命令,一般都是权限引起的,

$ sudo gem install githug

安装成功后,随便进入一个目录,也可新建一个目录,然后敲入

$ githug

会提示你 githug 目录找不到,是否创建一个,

********************************************************************************
*                                    Githug                                    *
********************************************************************************
No githug directory found, do you wish to create one? [yn]  

输入 y,会新建一个 githug 文件夹,cd githug 进去,就可以开始游戏了。

基本操作

这里我们首先熟悉下几个基本操作:

  • play 检查是否过关,每一关完成后用 githug play 检查一下,就可以知道有没有答对
  • hint 这是我最常用的一个操作,会显示本关卡的过关提示
  • reset 重置关卡,有时候答错了,环境已经变了,此时万一你输入了正确的答案,结果还是错的,因为你前面的环境已经被“污染”了,所以每当答错题目,记得 githug reset 一遍
  • levels 显示关卡列表,目前一共有 54 关

示例

因为我目前处于 44 关卡,我就拿这个关卡做为一个示例吧,首先重置下,

$ githug reset 


➜  git_hug git:(master) githug reset
********************************************************************************
*                                    Githug                                    *
********************************************************************************
resetting level

Name: rename_commit
Level: 44
Difficulty: ***

Correct the typo in the message of your first (non-root) commit.

从输出的内容上可以看到有题目的名字,关卡数和难度。难度下面是本题目的通关内容。好,我们现在来做题。

rename_commit,顾名思义,就是重命名 commit 的内容,“Correct the typo in the message of your first (non-root) commit”,"typo" 是什么鬼?查了一下,原来是“错别字”的意思,好了,现在明白题目的意思了,就是让我们找到 "first commit" 的那条commit 然后纠正我们的错误信息。

$ git log

0e5689e (HEAD -> master) Second commit
bf48411 First coommit
008128a Initial commit
(END) 

OK,这是一道很好的题目,之前我也遇到了这种情况,比如还没写完 commit 的 message ,然后一不小心就按下了回车,结果就把 commit 提交上去了,这时候却不知道怎么修改,之前的我是选择忽略的。。。,现在既然又遇到了,那就把它弄个明白吧,可是怎么做好呢?我们来看下提示。

$ githug hint

********************************************************************************
*                                    Githug                                    *
********************************************************************************
Take a look the `-i` flag of the rebase command.

"Take a look the -i flag of the rebase command.", 输入

$ git rebase --help

会看到很详细的说明文档,我们找到带 -i 那条说明,

-i, --interactive
           Make a list of the commits which are about to be rebased. Let the user edit
           that list before rebasing. This mode can also be used to split commits (see
           SPLITTING COMMITS below).
           

ok,找到 First coommit 的 commit id,敲入

$ git rebase -i bf48411

pick 0e5689e Second commit

# Rebase bf48411..0e5689e onto bf48411 (1 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
~                                             

好像看不到有 "First coommit" 的信息啊?咋回事?后面发现,原来 -i 指向的是我们要修改的前一条 commit,重来,输入 Initial commit 的 id,

$ git rebase -i 008128a

pick bf48411 First coommit
pick 0e5689e Second commit

# Rebase 008128a..0e5689e onto 008128a (2 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

终于看到了熟悉的字眼了,把 First coommit 那条的 pick 改成 edit,然后保存。

pick bf48411 First coommit --> edit bf48411 First coommit

➜  git_hug git:(master) git rebase -i 008128a
Stopped at bf48411792b6e9e2e36407983e40e0610a3febf2... First coommit
You can amend the commit now, with

    git commit --amend 

Once you are satisfied with your changes, run

    git rebase --continue


此时要 git commit --amend 了,

➜  git_hug git:(bf48411) git commit --amend -m "First commit"
[detached HEAD 63e13d1] First commit
 Date: Tue Feb 2 10:35:06 2016 +0800
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1

最后还要 git rebase --continue,因为

--continue
           Restart the rebasing process after having resolved a merge conflict.
➜  git_hug git:(63e13d1) git rebase --continue 
Successfully rebased and updated refs/heads/master.

Ok,验证一下,

➜  git_hug git:(master) githug play
********************************************************************************
*                                    Githug                                    *
********************************************************************************
Congratulations, you have solved the level!

Name: squash
Level: 45
Difficulty: ****

You have committed several times but would like all those changes to be one commit.

通关咯!!!下面紧接的是 45关,这里我就不再示例了,伙伴们,赶紧搞起来吧!学习 git,从此不再枯燥无味。

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

推荐阅读更多精彩内容

  • 在游戏中学习Git之Githug(Windows版) 1. githug安装 首先,下载Git工具,并配置Git工...
    lavor阅读 6,621评论 1 17
  • git常用命令 GIT常用命令备忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章阅读 8,478评论 1 26
  • 早高峰想打车,是比登天还难的。送儿子上幼儿园,去晚了就没饭吃,厚着脸皮和人拼车。 那个乘客大叔不想让我上去,明明顺...
    米丝桃阅读 306评论 0 1
  • 我醉了 在这无人的夜里 像疯子一样 苦闷的灌下啤酒 我哭了 在这皎洁的月下 像傻子一样 默默的独自思考 我到底是在...
    白树先生阅读 127评论 5 2
  • 我真心的很难受,没有那天比今天还难受,曾有一瞬间绝觉得我是不是多余的。
    一夜如梦阅读 199评论 0 0