'githug'是一個(gè)跟'learnyournode'差不多的通關(guān)github,在浪費(fèi)了一個(gè)可以看電影的下午牵囤,我把這個(gè)并沒有什么卵用的東西寫了寫。你需要做的很簡(jiǎn)單:follow the instructions滞伟。首先check一下電腦上ruby的環(huán)境揭鳞,然后直接安裝
$ gem install githug
$githug
然后就能看見一個(gè)闖關(guān)的基本界面,在每次完成后記得問githug這樣對(duì)不對(duì)就可以進(jìn)行到下一關(guān)了梆奈。
Level 1: initialize an empty repository
$ git init
Level 2 Set up name and email
$ git config user.name "CatAmo10"
$ git config user.email CatAmo10@example.com
Level 3 add 'README' files in folder to staging area
$ git add README
或者一般情況下野崇,當(dāng)我merge出了錯(cuò)我會(huì)直接用
$ git add .
把所有untracked文件都加上
Level 4 Commit file
$ git commit -m "your own commit message"
一般如果說(shuō)沒有change,只是修改文件亩钟,我會(huì)用
$ git commit -am "your own commit message"
Level 5 Clone a repo
$ git clone https://github.com/Gazler/clonename
Level 6 clone to a folder
$ git clone https://github.com/Gazler/clonename my_cloned_repo
Level 7 ignore files
修改文件.gitirnore
$ vim .gitignore
在文件中加上
*.swp
忽略所有尾綴為'.swp'的文件
Level 8
和上一步操作一樣乓梨,只需要忽略所有'.a'文件,并加上
!lib.a
Level 9 Status
$ git status
Level 10
跟上一步還是一樣的清酥,查看一下status
Level 11 remove files
第一步扶镀,檢查被remove的文件
$ git checkout
第二步
$ git rm deleteme.rb
Level 12 remove files added to staging ara which you do not want
$git rm --cached deleteme.rb
Level 13 save changes without commit
$ git stash
Level 14 rename file name
git mv oldfile.txt newfile.txt
Level 15 Restructure, move all the files
$ mkdir src
$ git mv *.html src
Level 16 log
$ git log
Level 17 tag
$ git tag new_tag
Level 18 push tags
$ git push --tags
Level 19 Commit amend
$ git add forgotten_file.rb
$ git commit --amend
Level 20 commit files with specific dates
$ git commit --date=03.01.2016T14:09:05
Level 21 reset
$ git reset HEAD to_commit_second.rb
Level 22 reset soft
如果放回working directory應(yīng)該就要checkout這個(gè)file了,但是reset soft只是放回了staging area
$ git reset --soft HEAD^
Level 23 checkout files
$ git checkout config.rb
Level 24 remote
$ git remote
Level 25 remote url
$ git remote url
Level 26 pull changes
$ git pull origin master
Level 27 add a new remote
$ git remote add origin https://github.com/githug/githug
Level 28 rebase commit onto master
$ git rebase origin/master master
$ git push origin master
Level 29 diff
$ git diff
Level 30 blame
$ git blame config.rb
Level 31 create a branch
$ git brahch test_code
Level 32 switch to another branch
$git branch mybranch
$ git checkout mybranch
Level 33 checkout a tag
$ git checkout v1.2
Level 34 checkout a tag with the same-name branch
$ git checkout tags/v1.2
Level 35 create a branch at previou commit
$ git branch test_branch HEAD^
Level 36 delete a branch
$ git branch -d delete_me
Level 37 push specific branch to remote
$ git push origin test_branch
Level 38 merge
$ git merge feature
Level 39 fetch
我覺得fetch和pull的區(qū)別在于焰轻,pull相當(dāng)于fetch了之后再merge臭觉,所以此處應(yīng)該有fetch
$ git fetch origin
LEvel 40 rebase
$ git rebase feature
$ git checkout feature
$ git rebase -i master
Level 41 repack
$ git repack
$ git repack -d
Level 42 cherry-pick
我第一次聽到這么好聽的命令,但是...我依舊沒太明白這個(gè)優(yōu)雅的命令有什么大用途,我簡(jiǎn)單的認(rèn)為這是一種附有強(qiáng)烈處女情結(jié)的merge蝠筑,只挑某個(gè)branch上的一個(gè)commit引入master而不是僅僅去merge兩個(gè)分支忆肾。我猜想log會(huì)變得更好看一些。
首先要把那個(gè)看上去does not make any sense的長(zhǎng)長(zhǎng)的SHA碼找到
$ git checkout new-feature
$ git log
$ git checkout master
$ git cherry-pick ca32a6d
Level 43 grep check TODOs
$ git grep TODO
Level 44 rename the commit
again菱肖、還是要check一下log
$ git log
復(fù)制第一個(gè)commit地址
$ git rebase i ffc13cc
現(xiàn)在你能看到文件中幾個(gè)命令客冈,文件是按照命令順序自上而下運(yùn)行,所以只要在第一句前面加上reword就行了
Level 45 merge multiple commit to one
還記得上一步中的文件中有一個(gè)命令叫做squash嗎稳强?對(duì)squash標(biāo)準(zhǔn)解釋是受擠壓场仲,就是簡(jiǎn)單地把幾次commit擠壓成一次
$ git log
$ git rebase i
把最終輸出的那唯一一個(gè)commit留著,其他均改成squash
Level 46 merge squash, merge all commits
$ git merge --squash long-feature-branch
Level 47 reorder
$ git rebase i 85d671
記得check一下log退疫,然后直接修改文件的命令順序渠缕,自上而下
Level 48 bisect
$ git bisect start
如果這個(gè)時(shí)候直接 'git bisect run make test'就會(huì)跳出幫助,必須有set bad或者good之后才能run test
ruby prog.rb 5
git bisect bad
$ git log
$ git checkout 5db7a7c
ruby prog.rb 5
git bisect good
...
總之一直循環(huán)到可以運(yùn)行
$ git bisect run make test
Level 49 stage one file in first feature
$ git add -p
然后選擇'n'褒繁,手動(dòng)修改亦鳞,直接將second feature刪掉
Level 50 find an old branch
$ git reflog
$ git checkout solve_world_hunger
Level 51 revert, redo middle commit not changing existing history
$ git revert HEAD^1
Level 52 restore a deteleted commit
$ git log
$ git checkout 3d5de5f
Level 53 conflict
$ git merge mybranch
發(fā)現(xiàn)在poem.txt中又conflict,所以現(xiàn)在需要修改文件poem.txt
$ vim poem.txt
為以防萬(wàn)一棒坏,再加上所有untracked文件
$ git add .
$ git commit
$ git merge mybranch
Level 54 submodule
git submodule https://github.com/jackmoney/githug-include-me ./githug-include-me
當(dāng)?shù)竭@一步的時(shí)候就結(jié)束了燕差,你需要做的就是fork這個(gè)github項(xiàng)目,并加上一些自己的Level