Githug 闯关式学习 git(一)

Githug is designed to give you a practical way of learning git. It has a series of levels, each requiring you to use git commands to arrive at a correct answer.

Githug 基于 Ruby,所以首先要具备 Ruby 环境,然后安装 githug(https://github.com/Gazler/githug )。

PS: gem 速度不佳,请使用淘宝的镜像:https://ruby.taobao.org/

Githug 并不能够让你掌握所有的 git 命令,它仅提供对 git 一些重要特性的指引。在最初学习 git 的过程中,往往遇不到很多的使用情景,命令繁多而不知用在何处。而 Githug 则在一些小例子中对 git 的知识进行巩固。通过阅读提示和 git 自带的命令帮助,能够掌握大部分的 git 实用技能。若要详细了解 git 底层的原理及具体的功能细节,可以参考下面的书籍。

推荐及参考书籍:

《Pro git》
《Git 版本控制管理(第 2 版)》

以下是自己的闯关记录,供读者参考。


Level 1: init

1
$ git init

Level 2: config

1
2
$ git config --global user.name "Rainy"
$ git config --global user.email "[email protected]"

Level 3: add

1
$ git add .

Level 4: commit

1
$ git commit -m "First commit"

Level 5: clone

1
$ git clone https://github.com/Gazler/cloneme

Level 6: clone_to_folder

1
$ git clone https://github.com/Gazler/cloneme my_cloned_repo

Level 7: ignore

1
$ vi .gitignore # Add line "*.swp"

Level 8: include

1
$ vi .gitignore # Add line "*.a !lib.a"

Level 9: status

1
$ git status

Level 10: number_of_files_committed

1
$ git status

Level 11: rm

1
2
$ git add .
$ git commit -m "Delete deleteme.rb"

Level 12: rm_cached

1
$ git rm --cached deleteme.rb

Level 13: stash

1
$ git stash save

Level 14: rename

1
$ git mv oldfile.txt newfile.txt

Level 15: restructure

1
2
$ mkdir src
$ git mv *.html ./src

Level 16: log

1
$ git log -1

Level 17: tag

1
$ git tag -m "New tag" new_tag HEAD

Level 18: push_tags

1
$ git push origin master

Level 19: commit_amend

1
2
$ git add forgotten_file.rb
$ git commit --amend

Level 20: commit_in_future

1
$ git commit -m "future" --date="Sun Jan 3 13:40:06 2017 +0800"

Level 21: reset

1
2
$ git reset HEAD
$ git add to_commit_first.rb

Level 22: reset_soft

1
$ git reset --soft HEAD^

Level 23: checkout_file

1
$ git checkout config.rb

Level 24: remote

1
$ git remote -v

Level 25: remote_url

1
$ git remote -v

Level 26: pull

1
$ git pull origin master

Level 27: remote_add

1
$ git remote add origin https://github.com/githug/githug

Level 28: push

1
2
3
$ git pull origin master
$ git rebase origin/master master
$ git push origin master

Level 29: diff

1
$ git diff HEAD

Level 30: blame

1
$ git blame config.rb

Level 35: branch_at

1
2
3
4
$ git reset master^
$ git branch test_branch
$ git add .
$ git commit -m "Updating file1 again"

Level 36: delete_branch

1
$ git branch -d delete_me

Level 37: push_branch

1
$ git push origin test_branch

Level 38: merge

1
$ git merge feature master

Level 39: fetch

1
$ git fetch origin

Level 40: rebase

1
$ git rebase master feature

Level 41: repack

1
$ git repack -a -d

Level 42: cherry-pick

1
2
$ git checkout master
$ git cherry-pick new-feature~2

Level 43: grep

1
$ git grep TODO

Level 44: rename_commit

1
$ git rebase -i master~2

Level 45: squash

1
$ git rebase -i master~4

Level 46: merge_squash

1
2
3
$ git merge --squash long-feature-branch
$ git add .
$ git commit -m "Merge branch long-feature-branch"

Level 47: reorder

1
$ git rebase -i master~2

Level 48: bisect

1
2
3
4
$ git bisect start
$ git bisect bad
$ git bisect good [first commit]
$ ruby prog.rb 5 # 二分查找直至找出 bad 编辑提交指定行

Level 49: stage_lines

1
$ git add -p feature.rb # 编辑提交指定行

Level 50: find_old_branch

1
2
$ git reflog
$ git checkout solve_world_hunger

Level 51: revert

1
$ git revert master~1

Level 52: restore

1
2
$ git reflog
$ git reset --hard bcda

Level 53: conflict

1
2
3
4
$ git merge mybranch
# resolve conflicts and finish the merge
$ git add .
$ git commit -m "Fix merge"

Level 54: submodule

1
$ git submodule add https://github.com/jackmaney/githug-include-me githug-include-merge

Level 55: contribute

1
:)
本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明出处! © 雨落
沉淀,分享。