******************************************************************************** * 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.
******************************************************************************** * 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.
******************************************************************************** * Githug * ******************************************************************************** What is your name? foo What is your email? foo@foo.foo Your config has the following name: foo Your config has the following email: foo@foo.foo Congratulations, you have solved the level!
Name: add Level: 3 Difficulty: *
There is a file in your folder called `README`, you should add it to your staging area Note: You start each level with a new repo. Don't look for files from the previous one.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: commit Level: 4 Difficulty: *
The `README` file has been added to your staging area, now commit it.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: clone Level: 5 Difficulty: *
Clone the repository at https://github.com/Gazler/cloneme.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: clone_to_folder Level: 6 Difficulty: *
Clone the repository at https://github.com/Gazler/cloneme to `my_cloned_repo`.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: ignore Level: 7 Difficulty: **
The text editor 'vim' creates files ending in `.swp` (swap files) for all files that are currently open. We don't want them creeping into the repository. Make this repository ignore those swap files which are ending in `.swp`.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: include Level: 8 Difficulty: **
Notice a few files with the '.a' extension. We want git to ignore all but the 'lib.a' file.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: status Level: 9 Difficulty: *
There are some files in this repository, one of the files is untracked, which file is it?
➜ git_hug git:(master) ✗ git status On branch master
No commits yet
Changes to be committed: (use "git rm --cached <file>..." to unstage)
new file: Guardfile new file: README new file: config.rb new file: deploy.rb new file: setup.rb
Untracked files: (use "git add <file>..." to include in what will be committed)
database.yml
再执行githug,按照提示填写答案即可。
10. number_of_files_committed
1 2 3 4 5 6 7 8 9 10 11
******************************************************************************** * Githug * ******************************************************************************** What is the full file name of the untracked file? database.yml Congratulations, you have solved the level!
There are some files in this repository, how many of the files will be committed?
这一步几乎没什么难度,使用git status命令列出需要commit的文件,然后数出来就行了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
➜ git_hug git:(master) ✗ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
new file: rubyfile1.rb modified: rubyfile4.rb
Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
modified: rubyfile5.rb
Untracked files: (use "git add <file>..." to include in what will be committed)
rubyfile6.rb rubyfile7.rb
输入标绿项目个数即可通关。
11. rm
1 2 3 4 5 6 7 8 9 10 11
******************************************************************************** * Githug * ******************************************************************************** How many changes are going to be committed? 2 Congratulations, you have solved the level!
Name: rm Level: 11 Difficulty: **
A file has been removed from the working tree, however the file was not removed from the repository. Find out what this file was and remove it.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: rm_cached Level: 12 Difficulty: **
A file has accidentally been added to your staging area, find out which file and remove it from the staging area. *NOTE* Do not remove the file from the file system, only from git.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: stash Level: 13 Difficulty: **
You've made some changes and want to work on them later. You should save them, but don't commit them.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: rename Level: 14 Difficulty: ***
We have a file called `oldfile.txt`. We want to rename it to `newfile.txt` and stage this change.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: log Level: 16 Difficulty: **
You will be asked for the hash of most recent commit. You will need to investigate the logs of the repository for this.
******************************************************************************** * Githug * ******************************************************************************** What is the hash of the most recent commit? ceaaa51ad379466a167ea00d9aa426adc6f453c8 Congratulations, you have solved the level!
Name: tag Level: 17 Difficulty: **
We have a git repo and we want to tag the current commit with `new_tag`.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: push_tags Level: 18 Difficulty: **
There are tags in the repository that aren't pushed into remote repository. Push them now.
From /var/folders/_w/2d1v6tdn2md_1p8h0271w3q80000gn/T/d20180601-12051-1kxh5hq/ * [new branch] master -> origin/master
既然打好了tag,自然要push到远程仓库中。
1
git push origin master
19. commit_amend
1 2 3 4 5 6 7 8 9 10
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: commit_amend Level: 19 Difficulty: **
The `README` file has been committed, but it looks like the file `forgotten_file.rb` was missing from the commit. Add the file and amend your previous commit to include it.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: commit_in_future Level: 20 Difficulty: **
Commit your changes with the future date (e.g. tomorrow).
题目要求控制时间。
1
git commit --date='2018-06-02 00:00:00' -m 'commit on tomorrow'
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: reset Level: 21 Difficulty: **
There are two files to be committed. The goal was to add each file as a separate commit, however both were added by accident. Unstage the file `to_commit_second.rb` using the reset command (don't commit anything).
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: reset_soft Level: 22 Difficulty: **
You committed too soon. Now you want to undo the last commit, while keeping the index.
回退到上一次commit。 方法一
1
git reset --soft ^HEAD
方法二
1 2 3
# 查处上一次提交到commit ID git log git reset --soft b3ae865ce692d647ad6938a4273753ccc6923a96
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: remote Level: 24 Difficulty: **
This project has a remote repository. Identify it.
******************************************************************************** * Githug * ******************************************************************************** What is the name of the remote repository? my_remote_repo Congratulations, you have solved the level!
Name: remote_url Level: 25 Difficulty: **
The remote repositories have a url associated to them. Please enter the url of remote_location.
******************************************************************************** * Githug * ******************************************************************************** What is the url of the remote repository? https://github.com/githug/not_a_repo Congratulations, you have solved the level!
Name: pull Level: 26 Difficulty: **
You need to pull changes from your origin repository.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: remote_add Level: 27 Difficulty: **
Add a remote repository called `origin` with the url https://github.com/githug/githug
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
warning: no common commits remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From /var/folders/6g/6vz3_qrs2kn998mvx03p837w0000gn/T/d20160527-20512-1vbud0e/ * [new branch] master -> origin/master
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: diff Level: 29 Difficulty: **
There have been modifications to the `app.rb` file since your last commit. Find out which line has changed.
******************************************************************************** * Githug * ******************************************************************************** What is the number of the line which has changed? 26 Congratulations, you have solved the level!
Name: blame Level: 30 Difficulty: **
Someone has put a password inside the file `config.rb` find out who it was.
******************************************************************************** * Githug * ******************************************************************************** Who made the commit with the password? Spider Man Congratulations, you have solved the level!
Name: branch Level: 31 Difficulty: *
You want to work on a piece of code that has the potential to break things, create the branch test_code.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: checkout Level: 32 Difficulty: **
Create and switch to a new branch called my_branch. You will need to create a branch like you did in the previous level.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: checkout_tag Level: 33 Difficulty: **
You need to fix a bug in the version 1.2 of your app. Checkout the tag `v1.2`.
这一步和上一步类似,只是签出到tag上。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
➜ git_hug git:(master) git tag v1.0 v1.2 v1.5 ➜ git_hug git:(master) git checkout v1.2 Note: checking out 'v1.2'.
You are in'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at d46b40b Some more changes
34. checkout_tag_over_branch
1 2 3 4 5 6 7 8 9 10
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
You need to fix a bug in the version 1.2 of your app. Checkout the tag `v1.2` (Note: There is also a branch named `v1.2`).
当我们需要签出到某个特定的分支,但是分支(branch)名和标签(tag)名重合。
1
git checkout tags/v1.2
35. branch_at
1 2 3 4 5 6 7 8 9 10
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: delete_branch Level: 36 Difficulty: **
You have created too many branches for your project. There is an old branch in your repo called 'delete_me', you should delete it.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: push_branch Level: 37 Difficulty: **
You've made some changes to a local branch and want to share it, but aren't yet ready to merge it with the 'master' branch. Push only 'test_branch' to the remote repository
这一步是直接将本地分支推送到远程。
1
git push origin test_branch:test_branch
38. merge
1 2 3 4 5 6 7 8 9 10
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: merge Level: 38 Difficulty: **
We have a file in the branch 'feature'; Let's merge it to the master branch.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: fetch Level: 39 Difficulty: **
Looks like a new branch was pushed into our remote repository. Get the changes without merging them with the local repository
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: rebase Level: 40 Difficulty: **
We are using a git rebase workflow and the feature branch is ready to go into master. Let's rebase the feature branch onto our master branch.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: rebase_onto Level: 41 Difficulty: **
You have created your branch from `wrong_branch` and already made some commits, and you realise that you needed to create your branch from `master`. Rebase your commits onto `master` branch so that you don't have `wrong_branch` commits.
git rebase --onto A B C A代表的是你实际想要将切片放到哪个分支,B代表切片开始分支(一定要注意的问题是B的开闭问题,这里rebase --onto的机制是左开右闭)。
git rebase --onto A B~1 temp如果想要保留A和C的历史,就需要先在切片的末尾建立一个分支temp。这就代表把B到c之间的历史移到了A上,并且当前temp分支的历史状态就是我们想要的。
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: repack Level: 42 Difficulty: **
Optimise how your repository is packaged ensuring that redundant packs are removed.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: grep Level: 44 Difficulty: **
Your project's deadline approaches, you should evaluate how many TODOs are left in your code
➜ git_hug git:(master) git grep TODO app.rb:# TODO Make site url variable. app.rb:# TODO Make API version variable. app.rb:# TODO Redirecting queries could be useful. config.rb: # TODO Move password to a configuration file.
数出数目为4个,填写4即可通关。
45. rename_commit
1 2 3 4 5 6 7 8 9 10 11
******************************************************************************** * Githug * ******************************************************************************** How many items are there in your todolist? 4 Congratulations, you have solved the level!
Name: rename_commit Level: 45 Difficulty: ***
Correct the typo in the message of your first (non-root) commit.
对于手残党来说,commit出现笔误是常有的事。幸好我们可以使用下面的方法补救:
先通过git log找出错误信息在第几次提交;
通过git rebase -i HEAD~2;
后有个编辑界面,将错误信息所在的那个提交中的pick修改为edit,保存并退出;
之后执行git commit –amend修改提交的错误信息;
然后再执行git rebase –continue完成修改。
46. squash
1 2 3 4 5 6 7 8 9 10
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: squash Level: 46 Difficulty: ****
You have committed several times but would like all those changes to be one commit.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: merge_squash Level: 47 Difficulty: ***
Merge all commits from the long-feature-branch as a single commit.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: reorder Level: 48 Difficulty: ****
You have committed several times but in the wrong order. Please reorder your commits.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
这是Git的调试功能。顾名思义,这种调试是二分法调试。首先需要确定起始位置的commit ID,然后使用git bisect start传入ID,然后执行git bisect run make test,会自动逐个测试所有commit状态下的文件。最后定位到错误,填写定位到错误的commit ID前7位即可通关。
50. stage_lines
1 2 3 4 5 6 7 8 9 10 11
******************************************************************************** * Githug * ******************************************************************************** What are the first 7 characters of the hash of the commit that introduced the bug? 18ed2ac Congratulations, you have solved the level!
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.
这是对文件的部分修改进行提交的操作。平时的开发中也容易遇到此类需求,需要稍加留心。
使用git add -p FILE;
输入e回车,进入stage编辑页面,将属于第二次commit的内容注释或者删去。
51. find_old_branch
1 2 3 4 5 6 7 8 9 10
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
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.
******************************************************************************** * Githug * ******************************************************************************** Congratulations, you have solved the level!
Name: submodule Level: 55 Difficulty: **
You want to include the files from the following repo: `https://github.com/jackmaney/githug-include-me` into a the folder `./githug-include-me`. Do this without manually cloning the repo or copying the files from the repo into this repo.
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.