もた日記

くだらないことを真面目にやる

Gitメモ : 「Githug」演習形式でGitの基本的な使い方を学ぶ

Githug


github.com

Githugという演習形式でGitの基本的な使い方を学べるツールがあったので遊んでみた(5年前くらいからあるみたいだけど知らなかった)。

f:id:wonder-wall:20170907000645p:plain


インストール


Rubyで書いてあるのでgemでインストールする。

$ gem install githug

ヘルプメッセージ

$ githug --help
Tasks:
  githug help [TASK]  # Describe available tasks or one specific task
  githug hint         # Get a hint for the current level
  githug levels       # List all of the levels
  githug play         # Initialize the game
  githug reset        # Reset the current level
  githug test         # Test a level from a file path


使い方


最初に適当なディレクトリでgithugコマンドを実行する。ディレクトリを作成するか聞かれるのでyを入力するとgit_hugディレクトリが作成される。

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

Name: init
Level: 1
Difficulty: *

A new directory, `git_hug`, has been created; initialize an empty repository in it.

最初の問題はinitialize an empty repository in it.なのでgit_hugディレクトリに移動してgit initを実行する。

$ cd git_hug
$ git init
Initialized empty Git repository in /home/vagrant/git_hug/.git/

そして、githugを実行するとCongratulations〜と表示され次のレベルの問題が表示される。 このように正解と思われるコマンドを実行した後でgithugを実行して次のレベルに進んでいく。

$ githug
********************************************************************************
*                                    Githug                                    *
********************************************************************************
Congratulations, you have solved the level!

Name: config
Level: 2
Difficulty: *

Set up your git name and email, this is important so that your commits can be identified.

不正解の場合はSorry〜と表示されるので、再度挑戦する。

Sorry, this solution is not quite right!

答えがわからない場合はgithug hintを実行するとヒントが表示される(あまり参考にならないヒントも多いが)。

$ githug hint
********************************************************************************
*                                    Githug                                    *
********************************************************************************
You can type `git` in your shell to get a list of available git commands.

演習によってはファイルが既に作成されているが、間違ってファイルを削除した場合はgithug resetで元の状態に戻せる。gitのコマンドを色々実行してわけがわからなくなった場合もgithug resetとすればよい。

$ githug reset


全レベル


全てのレベルはlevelsで確認できる。現時点では56レベルまで。

$ githug levels
#1: init
#2: config
#3: add
#4: commit
#5: clone
#6: clone_to_folder
#7: ignore
#8: include
#9: status
#10: number_of_files_committed
#11: rm
#12: rm_cached
#13: stash
#14: rename
#15: restructure
#16: log
#17: tag
#18: push_tags
#19: commit_amend
#20: commit_in_future
#21: reset
#22: reset_soft
#23: checkout_file
#24: remote
#25: remote_url
#26: pull
#27: remote_add
#28: push
#29: diff
#30: blame
#31: branch
#32: checkout
#33: checkout_tag
#34: checkout_tag_over_branch
#35: branch_at
#36: delete_branch
#37: push_branch
#38: merge
#39: fetch
#40: rebase
#41: rebase_onto
#42: repack
#43: cherry-pick
#44: grep
#45: rename_commit
#46: squash
#47: merge_squash
#48: reorder
#49: bisect
#50: stage_lines
#51: find_old_branch
#52: revert
#53: restore
#54: conflict
#55: submodule
#56: contribute


難度3と4


難度は4まであり難度3と4の問題は下記。このあたりだとすぐに答えられないものもある。

Name: rename
Level: 14
Difficulty: ***

We have a file called `oldfile.txt`. We want to rename it to `newfile.txt`
and stage this change.
Name: restructure
Level: 15
Difficulty: ***

You added some files to your repository, but now realize that your project
needs to be restructured.  Make a new folder named `src` and using Git
move all of the .html files into this folder.
Name: checkout_file
Level: 23
Difficulty: ***

A file has been modified, but you don't want to keep the modification. 
Checkout the `config.rb` file from the last commit.
Name: push
Level: 28
Difficulty: ***

Your local master branch has diverged from the remote origin/master branch.
Rebase your commit onto origin/master and push it to remote.
Name: branch_at
Level: 35
Difficulty: ***

You forgot to branch at the previous commit and made a commit on top of it.
Create branch test_branch at the commit before the last.
Name: cherry-pick
Level: 43
Difficulty: ***

Your new feature isn't worth the time and you're going to delete it.
But it has one commit that fills in `README` file,
and you want this commit to be on the master as well.
Name: rename_commit
Level: 45
Difficulty: ***

Correct the typo in the message of your first (non-root) commit.
Name: squash
Level: 46
Difficulty: ****

You have committed several times but would like all those changes
to be one commit.
Name: merge_squash
Level: 47
Difficulty: ***

Merge all commits from the long-feature-branch as a single commit.
Name: reorder
Level: 48
Difficulty: ****

You have committed several times but in the wrong order.
Please reorder your commits.
Name: bisect
Level: 49
Difficulty: ***

A bug was introduced somewhere along the way.  You know that running
`ruby prog.rb 5` should output 15.  You can also run `make test`. 
What are the first 7 chars of the hash of the commit that introduced the bug.
Name: stage_lines
Level: 50
Difficulty: ****

You've made changes within a single file that belong to two different features,
but neither of the changes are yet staged. Stage only the changes
belonging to the first feature.
Name: find_old_branch
Level: 51
Difficulty: ****

You have been working on a branch but got distracted by a major issue and
forgot the name of it. Switch back to that branch.
Name: revert
Level: 52
Difficulty: ****

You have committed several times but want to undo the middle commit.
All commits have been pushed, so you can't change existing history.
Name: restore
Level: 53
Difficulty: ****

You decided to delete your latest commit by running `git reset --hard HEAD^`. 
(Not a smart thing to do.)  You then change your mind,
and want that commit back.  Restore the deleted commit.
Name: conflict
Level: 54
Difficulty: ****

You need to merge mybranch into the current branch (master).
But there may be some incorrect changes in mybranch which may cause conflicts.
Solve any merge-conflicts you come across and finish the merge.
Name: contribute
Level: 56
Difficulty: ***

This is the final level, the goal is to contribute to this repository
by making a pull request on GitHub. 
Please note that this level is designed to encourage you to add a valid
contribution to Githug, not testing your ability to create a pull request. 
Contributions that are likely to be accepted are levels, 
bug fixes and improved documentation.