最近在玩一個(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肥橙,從此不再枯燥無味魄宏。