學(xué)習(xí) git颂碧,從此不再枯燥無味

最近在玩一個(gè)叫 “githug” 的游戲,看到這個(gè)名字类浪,也許你馬上就聯(lián)想到了 git载城。是的,這是一個(gè)跟 git 相關(guān)的游戲费就,它把平乘咄撸可能遇到的一些場景都實(shí)例化,變成一個(gè)一個(gè)的關(guān)卡力细,通過通關(guān)的形式睬澡,讓你快速的學(xué)習(xí) Git 并發(fā)揮其最大的威力。

Github 地址在這里:《GitHug》眠蚂。

下面介紹下怎么安裝這個(gè)游戲煞聪。

安裝

因?yàn)?githug 是用 Ruby 編寫的,所以我們可以通過 gem 來安裝逝慧,安裝命令如下:

$ gem install githug

如果安裝失敗昔脯,就試試下面的命令啄糙,一般都是權(quán)限引起的,

$ sudo gem install githug

安裝成功后云稚,隨便進(jìn)入一個(gè)目錄隧饼,也可新建一個(gè)目錄,然后敲入

$ githug

會(huì)提示你 githug 目錄找不到静陈,是否創(chuàng)建一個(gè)燕雁,

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

輸入 y,會(huì)新建一個(gè) githug 文件夾鲸拥,cd githug 進(jìn)去拐格,就可以開始游戲了。

基本操作

這里我們首先熟悉下幾個(gè)基本操作:

  • play 檢查是否過關(guān)刑赶,每一關(guān)完成后用 githug play 檢查一下捏浊,就可以知道有沒有答對(duì)
  • hint 這是我最常用的一個(gè)操作,會(huì)顯示本關(guān)卡的過關(guān)提示
  • reset 重置關(guān)卡角撞,有時(shí)候答錯(cuò)了呛伴,環(huán)境已經(jīng)變了勃痴,此時(shí)萬一你輸入了正確的答案谒所,結(jié)果還是錯(cuò)的,因?yàn)槟闱懊娴沫h(huán)境已經(jīng)被“污染”了沛申,所以每當(dāng)答錯(cuò)題目劣领,記得 githug reset 一遍
  • levels 顯示關(guān)卡列表,目前一共有 54 關(guān)

示例

因?yàn)槲夷壳疤幱?44 關(guān)卡铁材,我就拿這個(gè)關(guān)卡做為一個(gè)示例吧尖淘,首先重置下,

$ 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.

從輸出的內(nèi)容上可以看到有題目的名字著觉,關(guān)卡數(shù)和難度村生。難度下面是本題目的通關(guān)內(nèi)容。好饼丘,我們現(xiàn)在來做題趁桃。

rename_commit,顧名思義,就是重命名 commit 的內(nèi)容肄鸽,“Correct the typo in the message of your first (non-root) commit”卫病,"typo" 是什么鬼?查了一下典徘,原來是“錯(cuò)別字”的意思蟀苛,好了,現(xiàn)在明白題目的意思了逮诲,就是讓我們找到 "first commit" 的那條commit 然后糾正我們的錯(cuò)誤信息帜平。

$ git log

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

OK,這是一道很好的題目幽告,之前我也遇到了這種情況,比如還沒寫完 commit 的 message 罕模,然后一不小心就按下了回車评腺,結(jié)果就把 commit 提交上去了,這時(shí)候卻不知道怎么修改淑掌,之前的我是選擇忽略的蒿讥。。抛腕。芋绸,現(xiàn)在既然又遇到了,那就把它弄個(gè)明白吧担敌,可是怎么做好呢摔敛?我們來看下提示。

$ 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

會(huì)看到很詳細(xì)的說明文檔全封,我們找到帶 -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" 的信息啊刹悴?咋回事行楞?后面發(fā)現(xiàn),原來 -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


此時(shí)要 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,因?yàn)?/p>

--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,驗(yàn)證一下解愤,

?  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.

通關(guān)咯!:趵颉送讲!下面緊接的是 45關(guān),這里我就不再示例了梦鉴,伙伴們李茫,趕緊搞起來吧!學(xué)習(xí) git肥橙,從此不再枯燥無味魄宏。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市存筏,隨后出現(xiàn)的幾起案子宠互,更是在濱河造成了極大的恐慌味榛,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,695評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件予跌,死亡現(xiàn)場離奇詭異搏色,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)券册,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,569評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門频轿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人烁焙,你說我怎么就攤上這事航邢。” “怎么了骄蝇?”我有些...
    開封第一講書人閱讀 168,130評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵膳殷,是天一觀的道長。 經(jīng)常有香客問我九火,道長赚窃,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,648評(píng)論 1 297
  • 正文 為了忘掉前任岔激,我火速辦了婚禮勒极,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘鹦倚。我一直安慰自己河质,他們只是感情好冀惭,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,655評(píng)論 6 397
  • 文/花漫 我一把揭開白布震叙。 她就那樣靜靜地躺著,像睡著了一般散休。 火紅的嫁衣襯著肌膚如雪媒楼。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,268評(píng)論 1 309
  • 那天戚丸,我揣著相機(jī)與錄音划址,去河邊找鬼。 笑死限府,一個(gè)胖子當(dāng)著我的面吹牛夺颤,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播胁勺,決...
    沈念sama閱讀 40,835評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼世澜,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了署穗?” 一聲冷哼從身側(cè)響起寥裂,我...
    開封第一講書人閱讀 39,740評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤嵌洼,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后封恰,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體麻养,經(jīng)...
    沈念sama閱讀 46,286評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,375評(píng)論 3 340
  • 正文 我和宋清朗相戀三年诺舔,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了鳖昌。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,505評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡低飒,死狀恐怖遗遵,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情逸嘀,我是刑警寧澤车要,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布,位于F島的核電站崭倘,受9級(jí)特大地震影響翼岁,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜司光,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,873評(píng)論 3 333
  • 文/蒙蒙 一琅坡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧残家,春花似錦榆俺、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,357評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至回窘,卻和暖如春诺擅,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背啡直。 一陣腳步聲響...
    開封第一講書人閱讀 33,466評(píng)論 1 272
  • 我被黑心中介騙來泰國打工烁涌, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人酒觅。 一個(gè)月前我還...
    沈念sama閱讀 48,921評(píng)論 3 376
  • 正文 我出身青樓撮执,卻偏偏與公主長得像,于是被迫代替她去往敵國和親舷丹。 傳聞我的和親對(duì)象是個(gè)殘疾皇子抒钱,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,515評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 在游戲中學(xué)習(xí)Git之Githug(Windows版) 1. githug安裝 首先,下載Git工具,并配置Git工...
    lavor閱讀 6,625評(píng)論 1 17
  • git常用命令 GIT常用命令備忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章閱讀 8,491評(píng)論 1 26
  • 早高峰想打車继效,是比登天還難的症杏。送兒子上幼兒園,去晚了就沒飯吃瑞信,厚著臉皮和人拼車厉颤。 那個(gè)乘客大叔不想讓我上去,明明順...
    米絲桃閱讀 307評(píng)論 0 1
  • 我醉了 在這無人的夜里 像瘋子一樣 苦悶的灌下啤酒 我哭了 在這皎潔的月下 像傻子一樣 默默的獨(dú)自思考 我到底是在...
    白樹先生閱讀 130評(píng)論 5 2
  • 我真心的很難受凡简,沒有那天比今天還難受逼友,曾有一瞬間絕覺得我是不是多余的。
    一夜如夢閱讀 199評(píng)論 0 0