美文网首页
GitHug 通关攻略(用来练习你的git技能)

GitHug 通关攻略(用来练习你的git技能)

作者: zevilan | 来源:发表于2019-02-23 11:28 被阅读0次

    Githug ?
    对,你没看错!!不是 GitHub,是GitHug。那么他跟 Git 什么关系? 和游戏又有什么关系?

    不知道版本控制工具git、没基础的墙裂建议先食用:廖雪峰Git教程

    这是一个命令行工具被设计来练习你的 Git 技能,该项目在这里:https://github.com/Gazler/githug ,它把平常可能遇到的一些场景都实例化,变成一个一个的关卡,一共有 55 个关卡,所以将他形象的形容为 Git 游戏。
    既然是游戏,作为一个专业的游戏玩家,通关自然是我的最终目标了!!!

    安装游戏
    没什么好说的,终端运行如下命令即可: sudo gem install githug

    githug命令行安装图示

    安装游戏完毕!


    1.查看帮助


    查看githug帮助

    2.游戏开始🔜
    直接输入 githug 就可以开始游戏了!开始的时候会询问是否创建文件夹,输入 y 确认创建,以后的操作将都在这个文件夹中进行。

    游戏开始

    第01关 init

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: init
    Level: 1
    Difficulty: *
    
    A new directory, `git_hug`, has been created; initialize an empty repository in it.
    
    
    提示:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You can type `git` in your shell to get a list of available git commands.
    
    
    git init
    
    

    第02关 config

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: config
    Level: 2
    Difficulty: *
    
    Set up your git name and email, this is important so that your commits can be identified.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    These settings are config settings.  You should run `git help config` if you are stuck.
    
    
    答案:
    git config --global user.name zevilan
    git config --global user.email zevilan@163.com
    git config --list
    
    

    第03关 add

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You can type `git` in your shell to get a list of available git commands.
    
    
    答案:
    git add README
    
    

    第04关 commit

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: commit
    Level: 4
    Difficulty: *
    
    The `README` file has been added to your staging area, now commit it.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You must include a message when you commit.
    
    
    答案:
    git commit -m "add README"
    
    

    第05关 clone

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: clone
    Level: 5
    Difficulty: *
    
    Clone the repository at https://github.com/Gazler/cloneme.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You should have a look at this site: https://github.com/Gazler/cloneme.
    
    
    答案:
    git clone https://github.com/Gazler/cloneme
    
    

    第06关 clone_to_folder

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: clone_to_folder
    Level: 6
    Difficulty: *
    
    Clone the repository at https://github.com/Gazler/cloneme to `my_cloned_repo`.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    This is like the last level, `git clone` has an optional argument.
    
    
    答案:
    git clone https://github.com/Gazler/cloneme my_cloned_repo
    
    

    第07关 ignore

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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 `.swp` files.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You may have noticed there is a file named `.gitignore` in the repository.
    
    
    答案:
    echo '*.swp' >> .gitignore
    
    

    第08关 include

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Using `git gitignore --help`, read about the optional prefix to negate a pattern.
    
    
    答案:
    echo '*.a' >> .gitignore
    echo '!lib.a' >> .gitignore
    
    

    第09关 status

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: status
    Level: 9
    Difficulty: *
    
    There are some files in this repository, one of the files is untracked, which file is it?
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You are looking for a command to identify the status of the repository.
    
    
    答案:
    git status
    
    

    第10关 number_of_files_committed

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: number_of_files_committed
    Level: 10
    Difficulty: *
    
    There are some files in this repository, how many of the files will be committed?
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You are looking for a command to identify the status of the repository.
    
    
    答案:
    git status
    
    

    第11关 rm

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You may need to use more than one command to complete this.  You have checked your staging area in a previous level.  Don't forget to run `git` for a list of commands.
    
    
    答案:
    git status
    git rm deleteme.rb
    
    

    第12关 rm_cached

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You may need to use more than one command to complete this.  You have checked your staging area in a previous level.  Don't forget to run `git` for a list of commands.
    
    
    答案:
    git status
    git rm --cached deleteme.rb
    
    ------------------------------
    git status
    git reset HEAD -- deleteme.rb
    
    

    第13关 stash

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    It's like stashing. Try finding appropriate git command.
    
    
    答案:
    git stash
    
    

    第14关 rename

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Take a look at `git mv`.
    
    
    答案:
    git mv oldfile.txt newfile.txt
    
    

    第15关 restructure

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You'll have to use mkdir, and `git mv`.
    
    
    答案:
    mkdir src
    git mv *.html src
    
    

    第16关 log

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You need to investigate the logs.  There is probably a command for doing that!
    
    
    答案:
    git log
    
    

    第17关 tag

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: tag
    Level: 17
    Difficulty: **
    
    We have a git repo and we want to tag the current commit with `new_tag`.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look at `git tag`.
    
    
    答案:
    git tag new_tag
    
    

    第18关 push_tags

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: push_tags
    Level: 18
    Difficulty: **
    
    There are tags in the repository that aren't pushed into remote repository. Push them now.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look at `--tags` flag of `git push`
    
    
    答案:
    git tag
    git push --tags
    
    

    第19关 commit_amend

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Running `git commit --help` will display the man page and possible flags.
    
    
    答案:
    git status
    git add forgotten_file.rb
    git commit --amend
    
    

    第20关 commit_in_future

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: commit_in_future
    Level: 20
    Difficulty: **
    
    Commit your changes with the future date (e.g. tomorrow).
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Build a time machine, move to the future and commit your changes, then go back and verify results ;).
    
    
    答案:
    git status
    git commit --date="$(date -R --date='+1 day')" -m "commit in future"
    git commit --date=05.22.2016T11:13
    
    

    第21关 reset

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You can get some useful information for git status, it will tell you the command you need to run.
    
    
    答案:
    git status
    git reset HEAD to_commit_second.rb
    ------------------------------------
    git status
    git rm --cached to_commit_second.rb
    
    

    第22关 reset_soft

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: reset_soft
    Level: 22
    Difficulty: **
    
    You committed too soon. Now you want to undo the last commit, while keeping the index.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    What are some options you can use with `git reset`?
    
    
    答案:
    git reset --soft HEAD~
    
    

    第23关 checkout_file

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You will need to do some research on the checkout command for this one.
    
    
    答案:
    git status
    git checkout -- config.rb
    
    

    第24关 remote

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: remote
    Level: 24
    Difficulty: **
    
    This project has a remote repository.  Identify it.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You are looking for a remote.  You can run `git` for a list of commands.
    
    
    答案:
    git remote
    
    

    第25关 remote_url

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: remote_url
    Level: 25
    Difficulty: **
    
    The remote repositories have a url associated to them.  Please enter the url of remote_location.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You can run `git remote --help` for the man pages.
    
    
    答案:
    git remote -v
    
    

    第26关 pull

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: pull
    Level: 26
    Difficulty: **
    
    You need to pull changes from your origin repository.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Check out the remote repositories and research `git pull`.
    
    
    答案:
    git pull origin master
    
    

    第27关 remote_add

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: remote_add
    Level: 27
    Difficulty: **
    
    Add a remote repository called `origin` with the url https://github.com/githug/githug
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You can run `git remote --help` for the man pages.
    
    
    答案:
    git remote
    git remote add origin https://github.com/githug/githug
    git remote -v
    
    

    第28关 push

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look at `git fetch`, `git pull`, and `git push`.
    
    
    答案:
    git status
    git push origin/master
    git status
    git push
    
    

    第29关 diff

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You are looking for the difference since your last commit.  Don't forget that running `git` on its own will list the possible commands.
    
    
    答案:
    git status
    git diff app.rb
    
    git diff: 查看 working directory 与 staging area 之间的差异
    git diff --cached: 查看 repository 与 staging area 之间的差异
    git diff HEAD: 查看 working directory 与 repository 之间的差异
    
    

    第30关 blame

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: blame
    Level: 30
    Difficulty: **
    
    Someone has put a password inside the file `config.rb` find out who it was.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You want to research the `git blame` command.
    
    
    答案:
    git blame config.rb
    
    

    第31关 branch

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    `git branch` is what you want to investigate.
    
    
    答案:
    git branch
    git branch test_code
    git branch
    
    

    第32关 checkout

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Try looking up `git checkout` and `git branch`.
    
    
    答案:
    git checkout -b my_branch
    git branch -a
    
    

    第33关 checkout_tag

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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`.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    There's no big difference between checking out a branch and checking out a tag.
    
    
    答案:
    git checkout v1.2
    
    

    第34关 checkout_tag_over_branch

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: checkout_tag_over_branch
    Level: 34
    Difficulty: **
    
    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`).
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You should think about specifying you're after the tag named `v1.2` (think `tags/`).
    
    
    答案:
    git branch -a
    git tag -l
    git checkout tags/v1.2
    
    

    第35关 branch_at

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Just like creating a branch, but you have to pass an extra argument.
    
    
    答案:
    git log
    git branch -vv test_branch 86fc5f #倒数第二条提交
    --------------------------------------------------
    git branch test_branch head~
    
    

    第36关 delete_branch

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Running 'git --help branch' will give you a list of branch commands.
    
    
    答案:
    git branch -d delete_me
    
    

    第37关 push_branch

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Investigate the options in `git push` using `git push --help`
    
    
    答案:
    git checkout test_branch
    git push --set-upstream origin test_branch
    ---------------------------------------------
    cat .git/config
    git checkout test_branch
    git push -u origin test_branch:test_branch
    cat .git/config
    ---------------------------------------------
    git branch -a
    git push origin test_branch
    git branch -a
    
    

    第38关 merge

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: merge
    Level: 38
    Difficulty: **
    
    We have a file in the branch 'feature'; Let's merge it to the master branch.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You want to research the `git merge` command.
    
    
    答案:
    git branch
    git merge feature
    --------------------------
    git branch
    git merge --no-ff feature
    
    

    第39关 fetch

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    Look up the 'git fetch' command
    
    
    答案:
    git branch -a
    git fetch
    git branch -a
    
    

    第40关 rebase

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting 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                                    *
    ********************************************************************************
    You want to research the `git rebase` command
    
    
    答案:
    git branch
    git log
    git checkout feature
    git log
    git rebase master
    git log
    -------------------------------
    git log --graph --all
    git rebase master feature
    git log --graph --all
    
    

    第41关 repack

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: repack
    Level: 41
    Difficulty: **
    
    Optimise how your repository is packaged ensuring that redundant packs are removed.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You want to research the `git repack` command.
    
    
    答案:
    git repack
    git prune-packed
    --------------------------
    git repack -d
    --------------------------
    git gc
    
    

    第42关 cherry-pick

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: cherry-pick
    Level: 42
    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                                    *
    ********************************************************************************
    Sneak a peek at the `cherry-pick` command.
    
    
    答案:
    git branch
    git log new-feature
    git cherry-pick ca32a6
    ---------------------------------
    git log --all --graph
    git cherry-pick ca32a6
    git log --all --graph
    
    

    第43关 grep

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: grep
    Level: 43
    Difficulty: **
    
    Your project's deadline approaches, you should evaluate how many TODOs are left in your code
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You want to research the `git grep` command.
    
    
    答案:
    git grep TODO
    
    

    第44关 rename_commit

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: rename_commit
    Level: 44
    Difficulty: ***
    
    Correct the typo in the message of your first (non-root) commit.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look the `-i` flag of the rebase command.
    
    
    答案:
    git log
    git rebase -i HEAD~2 #reword
    git log
    
    

    第45关 squash

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: squash
    Level: 45
    Difficulty: ****
    
    You have committed several times but would like all those changes to be one commit.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look the `-i` flag of the rebase command.
    
    
    答案:
    git log
    git rebase -i HEAD~4 #squash
    git log
    ------------------------
    git log
    git rebase -i --root #squash
    git log
    
    

    第46关 merge_squash

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: merge_squash
    Level: 46
    Difficulty: ***
    
    Merge all commits from the long-feature-branch as a single commit.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look at the `--squash` option of the merge command. Don't forget to commit the merge!
    git branch
    git status
    git merge --squash long-feature-branch
    git status
    git commit -a -m "merge commit"
    
    
    答案:
    git branch
    git status
    git merge --squash long-feature-branch
    git status
    git commit -a -m "merge commit"
    
    

    第47关 reorder

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: reorder
    Level: 47
    Difficulty: ****
    
    You have committed several times but in the wrong order. Please reorder your commits.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look the `-i` flag of the rebase command.
    
    
    答案:
    git log
    git rebase -i --root #reorder
    git log
    
    

    第48关 bisect

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: bisect
    Level: 48
    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.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    The fastest way to find the bug is with bisect.
    Don't forget to start bisect first, identify a good or bad commit, then run `git bisect run make test`.
    
    
    答案:
    git bisect start             
    git log --reverse -p prog.rb
    git bisect good v2.6.18
    git bisect bad master
    git bisect visualize
    git bisect run make test
    git show
    git bisect reset
    
    # 18ed2ac1
    ------------------------------------------
    git bisect start master f608824888b8
    git bisect run make test
    
    查找问题的利器 - Git Bisect
    http://gitbook.liuhui998.com/5_4.html
    
    git log 查看commit的历史
    git show <commit-hash-id>查看某次commit的修改内容
    git log -p <filename>查看某个文件的修改历史
    git log -p -2查看最近2次的更新内容
    
    

    第49关 stage_lines

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: stage_lines
    Level: 49
    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.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    You might want to try to manipulate the hunks of the diff to choose which lines of the diff get staged. Read about the flags which can be passed to the `add` command; `man git-add`.
    
    
    答案:
    git diff
    git add -p feature.rb
    git diff
    
    

    第50关 find_old_branch

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: find_old_branch
    Level: 50
    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                                    *
    ********************************************************************************
    Ever played with the `git reflog` command?
    
    
    答案:
    git reflog
    git checkout solve_world_hunger
    
    

    第51关 revert

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: revert
    Level: 51
    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                                    *
    ********************************************************************************
    Try the revert command.
    
    
    答案:
    git log
    git revert HEAD^
    git log
    -------------------
    git log
    git revert HEAD~1
    git log
    
    

    第52关 restore

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: restore
    Level: 52
    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                                    *
    ********************************************************************************
    The commit is still floating around somewhere.  Have you checked out `git reflog`?
    
    
    答案:
    git reflog
    git checkout 0a5ed8c
    
    

    第53关 conflict

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: conflict
    Level: 53
    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                                    *
    ********************************************************************************
    First you have to do a merge. Then resolve any conflicts and finish the merge
    Take a look at the sections on merge conflicts in 'git merge'.
    Remove the unnecessary lines in `poem.txt`, so only the correct poem remains.
    
    
    答案:
    git branch
    git merge --no-ff mybranch
    git status
    vim poem.txt
    git add poem.txt
    git commit -m "merge mybranch"
    
    

    第54关 submodule

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: submodule
    Level: 54
    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 cloning the repo or copying the files from the repo into this repo.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Take a look at `git submodule`.
    
    
    答案:
    git submodule add https://github.com/jackmaney/githug-include-me
    ls -al
    
    

    第55关 contribute

    问题:
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    resetting level
    
    Name: contribute
    Level: 55
    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.
    
    
    提示:
    
    ********************************************************************************
    *                                    Githug                                    *
    ********************************************************************************
    Forking the repository would be a good start!
    
    
    答案:
    嘿嘿,该干嘛干嘛去~
    
    

    感谢你选择查看本教程

    相关文章

      网友评论

          本文标题:GitHug 通关攻略(用来练习你的git技能)

          本文链接:https://www.haomeiwen.com/subject/swguyqtx.html