最近发现了githug一个小游戏是帮助学习git的各种命令 玩了几遍 把部分代码贴出来

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Sorry, this solution is not quite right!

Name: init

Level: 1

Difficulty: *

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

liyachao@ubuntu:~/git_hug$ git init

Initialized empty Git repository in /home/liyachao/git_hug/.git/

liyachao@ubuntu:~/git_hug$ 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.

liyachao@ubuntu:~/git_hug$ git config user.name "liyachao"//自己的名字

liyachao@ubuntu:~/git_hug$ git config user.email "296777513@qq.com"//自己的邮箱

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

What is your name? liyachao

What is your email? 296777513@qq.com

Your config has the following name: liyachao

Your config has the following email: 296777513@qq.com

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.

liyachao@ubuntu:~/git_hug$ ls

README

liyachao@ubuntu:~/git_hug$ git add README

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git commit -m "first commit"

[master (root-commit) 15de50d] first commit

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: clone

Level: 5

Difficulty: *

Clone the repository at https://github.com/Gazler/cloneme.

liyachao@ubuntu:~/git_hug$ git clone https://github.com/Gazler/cloneme

Cloning into 'cloneme'...

remote: Counting objects: 7, done.

remote: Total 7 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (7/7), done.

Checking connectivity... done.

liyachao@ubuntu:~/git_hug$ ls

cloneme

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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`.

liyachao@ubuntu:~/git_hug$ git clone https://github.com/Gazler/cloneme my_cloned_repo

Cloning into 'my_cloned_repo'...

remote: Counting objects: 7, done.

remote: Total 7 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (7/7), done.

Checking connectivity... done.

liyachao@ubuntu:~/git_hug$ ls

my_cloned_repo

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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 `.swp` files.

liyachao@ubuntu:~/git_hug$ vim .gitignore

*.gitignore

liyachao@ubuntu:~/git_hug$ ls

README.swp

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ vim .gitignore

*.a

!lib.a

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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?

liyachao@ubuntu:~/git_hug$ gitstatus

No command 'gitstatus' found, did you mean:

Command 'gitstats' from package 'gitstats' (universe)

gitstatus: command not found

liyachao@ubuntu:~/git_hug$ git status

On branch master

Initial commit

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

liyachao@ubuntu:~/git_hug$ ls

config.rb  database.yml  deploy.rb  Guardfile  README  setup.rb

liyachao@ubuntu:~/git_hug$ git add database.yml

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

What is the full file name of the untracked file? database.yml

Congratulations, you have solved the level!

Name: number_of_files_committed

Level: 10

Difficulty: *

There are some files in this repository, how many of the files will be committed?

liyachao@ubuntu:~/git_hug$ 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

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git status

On branch master

Changes not staged for commit:

(use "git add/rm <file>..." to update what will be committed)

(use "git checkout -- <file>..." to discard changes in working directory)

deleted:    deleteme.rb

no changes added to commit (use "git add" and/or "git commit -a")

liyachao@ubuntu:~/git_hug$ git rm deleteme.rb

rm 'deleteme.rb'

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git status

On branch master

Initial commit

Changes to be committed:

(use "git rm --cached <file>..." to unstage)

new file:   deleteme.rb

liyachao@ubuntu:~/git_hug$ git rm --cached deleteme.rb

rm 'deleteme.rb'

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

It's like stashing. Try finding appropriate git command.

liyachao@ubuntu:~/git_hug$ ls

lyrics.txt

liyachao@ubuntu:~/git_hug$ git stash

Saved working directory and index state WIP on master: 0206059 Add some lyrics

HEAD is now at 0206059 Add some lyrics

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Take a look at `git mv`.

liyachao@ubuntu:~/git_hug$ git status

On branch master

nothing to commit, working directory clean

liyachao@ubuntu:~/git_hug$ git mv oldfile.txt  newfile.txt

liyachao@ubuntu:~/git_hug$ ls

newfile.txt

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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 move all of the .html files into this folder.

liyachao@ubuntu:~/git_hug$ mkdir src

liyachao@ubuntu:~/git_hug$ git mv *.html src/

liyachao@ubuntu:~/git_hug$ git status

On branch master

Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

renamed:    about.html -> src/about.html

renamed:    contact.html -> src/contact.html

renamed:    index.html -> src/index.html

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git log

commit a07bf4d1f7491e785ecd5bb1c717a0d492d04bc5

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 18:13:10 2014 +0800

THIS IS THE COMMIT YOU ARE LOOKING FOR!

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

What is the hash of the most recent commit? a07bf4d1f7491e785e

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`.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Take a look at `git tag`.

liyachao@ubuntu:~/git_hug$ git tag

liyachao@ubuntu:~/git_hug$ git tag new_tag

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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 /tmp/d20141018-3708-cvfeu7/

* [new branch]      master     -> origin/master

liyachao@ubuntu:~/git_hug$ git push

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git status

On branch master

Untracked files:

(use "git add <file>..." to include in what will be committed)

forgotten_file.rb

nothing added to commit but untracked files present (use "git add" to track)

liyachao@ubuntu:~/git_hug$ git add forgotten_file.rb

liyachao@ubuntu:~/git_hug$ git commit --amend

[master 4eaa994] Initial commit

2 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README

create mode 100644 forgotten_file.rb

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: commit_in_future

Level: 20

Difficulty: **

Commit your changes with the future date (e.g. tomorrow).

这道题折磨了我两个小时,其实挺简单的就是到系统把时间设置成后一天,然后commit然后把时间调回来,再githug就好了

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Build a time machine, move to the future and commit your changes, then go back and verify results ;).

liyachao@ubuntu:~/git_hug$ git commit -m "future"

[master (root-commit) 26d6ac3] future

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README

liyachao@ubuntu:~/git_hug$ git status

On branch master

nothing to commit, working directory clean

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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).

iyachao@ubuntu:~/git_hug$ git status

On branch master

Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

new file:   to_commit_first.rb

new file:   to_commit_second.rb

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You can get some useful information for git status, it will tell you the command you need to run.

liyachao@ubuntu:~/git_hug$ git reset HEAD to_commit_second.rb

liyachao@ubuntu:~/git_hug$ git status

On branch master

Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

new file:   to_commit_first.rb

Untracked files:

(use "git add <file>..." to include in what will be committed)

to_commit_second.rb

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

What are some options you can use with `git reset`?

liyachao@ubuntu:~/git_hug$ git reset --soft HEAD~1

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You will need to do some research on the checkout command for this one.

liyachao@ubuntu:~/git_hug$ git status

On branch master

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:   config.rb

no changes added to commit (use "git add" and/or "git commit -a")

liyachao@ubuntu:~/git_hug$ git checkout config.rb

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: remote

Level: 24

Difficulty: **

This project has a remote repository.  Identify it.

liyachao@ubuntu:~/git_hug$ git remote -v

my_remote_repo https://github.com/Gazler/githug (fetch)

my_remote_repo https://github.com/Gazler/githug (push)

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

What is the name of the remote repository? https://github.com/Gazler/githug

Sorry, this solution is not quite right!

Name: remote

Level: 24

Difficulty: **

This project has a remote repository.  Identify it.

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git remote -v

my_remote_repo https://github.com/Gazler/githug (fetch)

my_remote_repo https://github.com/Gazler/githug (push)

remote_location https://github.com/githug/not_a_repo (fetch)

remote_location https://github.com/githug/not_a_repo (push)

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Check out the remote repositories and research `git pull`.

liyachao@ubuntu:~/git_hug$ git pull origin master

remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From https://github.com/pull-this/thing-to-pull

* branch            master     -> FETCH_HEAD

* [new branch]      master     -> origin/master

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You can run `git remote --help` for the man pages.

liyachao@ubuntu:~/git_hug$ git remote add https://github.com/githug/githug origin

fatal: 'https://github.com/githug/githug' is not a valid remote name

liyachao@ubuntu:~/git_hug$ git remote add origin https://github.com/githug/githug

liyachao@ubuntu:~/git_hug$ 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.

remote: Counting objects: 3, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 2 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (2/2), done.

From /tmp/d20141018-4696-1cn1bt1/

* [new branch]      master     -> origin/master

liyachao@ubuntu:~/git_hug$ git rebase origin/master

First, rewinding head to replay your work on top of it...

Applying: Third commit

liyachao@ubuntu:~/git_hug$ git push origin

warning: push.default is unset; its implicit value is changing in

Git 2.0 from 'matching' to 'simple'. To squelch this message

and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to 'matching', git will push local branches

to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'

behavior, which only pushes the current branch to the corresponding

remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.

(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode

'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 224 bytes | 0 bytes/s, done.

Total 2 (delta 1), reused 0 (delta 0)

To /tmp/d20141018-4788-12sto7d/.git

748cfe2..6cc17cf  master -> master

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git status

On branch master

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:   app.rb

no changes added to commit (use "git add" and/or "git commit -a")

liyachao@ubuntu:~/git_hug$ git diff app.rb

diff --git a/app.rb b/app.rb

index 4f703ca..3bfa839 100644

--- a/app.rb

+++ b/app.rb

@@ -23,7 +23,7 @@ get '/yet_another' do

erb :success

end

get '/another_page' do

-  @message = get_response('data.json')

+  @message = get_response('server.json')

erb :another

end

liyachao@ubuntu:~/git_hug$ vim app.rb

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You want to research the `git blame` command.

liyachao@ubuntu:~/git_hug$ git blame config.rb

^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000  1) class Config

70d00535 (Bruce Banner      2012-03-08 23:07:41 +0000  2)   attr_accessor :name, :pas

97bdd0cc (Spider Man        2012-03-08 23:08:15 +0000  3)   def initialize(name, pass

^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000  4)     @name = name

97bdd0cc (Spider Man        2012-03-08 23:08:15 +0000  5)     @password = password ||

00000000 (Not Committed Yet 2014-10-18 18:52:45 +0800  6)

09409480 (Spider Man        2012-03-08 23:06:18 +0000  7)     if options[:downcase]

09409480 (Spider Man        2012-03-08 23:06:18 +0000  8)       @name.downcase!

09409480 (Spider Man        2012-03-08 23:06:18 +0000  9)     end

70d00535 (Bruce Banner      2012-03-08 23:07:41 +0000 10)

ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 11)     if options[:upcase]

ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 12)       @name.upcase!

ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 13)     end

ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 14)

^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000 15)   end

^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000 16) end

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

`git branch` is what you want to investigate.

liyachao@ubuntu:~/git_hug$ git branch

* master

liyachao@ubuntu:~/git_hug$ git branch test_code

liyachao@ubuntu:~/git_hug$ git branch

* master

test_code

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git checkout -b my_branch

Switched to a new branch 'my_branch'

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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`.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

There's no big difference between checking out a branch and checking out a tag.

liyachao@ubuntu:~/git_hug$ git tag

v1.0

v1.2

v1.5

liyachao@ubuntu:~/git_hug$ 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 78e6f31... Some more changes

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the 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`).

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You should think about specifying you're after the tag named `v1.2` (think `tags/`).

liyachao@ubuntu:~/git_hug$ git checkout tags/v1.2

Note: checking out 'tags/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 7672f94... Some more changes

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git log

commit d611689e507995a70616b4886df8e794e91cc9bb

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:04:15 2014 +0800

Updating file1 again

commit f68688e6af93f94e6c839d90b30283e15af7324c

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:04:15 2014 +0800

Updating file1

commit 90d7e42cc7a217e17b6906c30bf82133d3e2cb6a

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:04:15 2014 +0800

Adding file1

liyachao@ubuntu:~/git_hug$ git branch test_branch -v 90d7e42cc7a217

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git branch

delete_me

* master

liyachao@ubuntu:~/git_hug$ git branch -D delete_me

Deleted branch delete_me (was b60afe2).

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Investigate the options in `git push` using `git push --help`

liyachao@ubuntu:~/git_hug$ git branch

* master

other_branch

test_branch

liyachao@ubuntu:~/git_hug$ git checkout other_branch

Switched to branch 'other_branch'

liyachao@ubuntu:~/git_hug$ git push origin test_branch

Counting objects: 7, done.

Compressing objects: 100% (6/6), done.

Writing objects: 100% (6/6), 656 bytes | 0 bytes/s, done.

Total 6 (delta 2), reused 0 (delta 0)

To /tmp/d20141018-5406-gu4ab5/.git

* [new branch]      test_branch -> test_branch

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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.

liyachao@ubuntu:~/git_hug$ git branch

feature

* master

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You want to research the `git merge` command.

liyachao@ubuntu:~/git_hug$ git merge feature

Updating e12277f..cc8ea5a

Fast-forward

file2 | 0

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 file2

liyachao@ubuntu:~/git_hug$ git branch

feature

* master

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    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

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Look up the 'git fetch' command

liyachao@ubuntu:~/git_hug$ git fetch

remote: Counting objects: 3, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 2 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (2/2), done.

From /tmp/d20141018-5534-fuemi9/

* [new branch]      new_branch -> origin/new_branch

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: repack

Level: 40

Difficulty: **

Optimise how your repository is packaged ensuring that redundant packs are removed.

这关题目是优化包。提示是用git repack 命令。可是我试了若干次都不行。查了各种资料发现有人说git gc可以替代git repacl来使用。我试了试,居然过关了。具体原因我还不太懂。先把结果记下来:

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You want to research the `git repack` command.

liyachao@ubuntu:~/git_hug$ git gc

Counting objects: 3, done.

Writing objects: 100% (3/3), done.

Total 3 (delta 0), reused 0 (delta 0)

liyachao@ubuntu:~/git_hug$ git hug

git: 'hug' is not a git command. See 'git --help'.

Did you mean one of these?

log

tag

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: cherry-pick

Level: 41

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.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Sneak a peek at the `cherry-pick` command.

liyachao@ubuntu:~/git_hug$ git branch

* master

new-feature

liyachao@ubuntu:~/git_hug$ git checkout new-feature

Switched to branch 'new-feature'

liyachao@ubuntu:~/git_hug$ git log

commit ea2a47c19b85fc321e2737ddc49db3deeba3a1b5

Author: Andrey <aslushnikov@gmail.com>

Date:   Wed Mar 28 02:28:35 2012 +0400

some small fixes

commit 4a1961bce62840eaef9c4392fe5cc799e38c9b7b

Author: Andrey <aslushnikov@gmail.com>

Date:   Wed Mar 28 02:27:18 2012 +0400

Fixed feature

commit ca32a6dac7b6f97975edbe19a4296c2ee7682f68

Author: Andrey <aslushnikov@gmail.com>

Date:   Wed Mar 28 02:25:51 2012 +0400

Filled in README.md with proper input

commit 58a8c8edcfdd00c6d8cce9aada8f987a1677571f

Author: Andrey <aslushnikov@gmail.com>

Date:   Wed Mar 28 02:24:41 2012 +0400

liyachao@ubuntu:~/git_hug$ git checkout master

Switched to branch 'master'

liyachao@ubuntu:~/git_hug$ git cherry-pick ca32a6dac7b6

[master 2559dbc] Filled in README.md with proper input

Author: Andrey <aslushnikov@gmail.com>

1 file changed, 1 insertion(+), 2 deletions(-)

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: grep

Level: 42

Difficulty: **

Your project's deadline approaches, you should evaluate how many TODOs are left in your code

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

You want to research the `git grep` command.

liyachao@ubuntu:~/git_hug$ 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.

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

How many items are there in your todolist? 4

Congratulations, you have solved the level!

Name: rename_commit

Level: 43

Difficulty: ***

Correct the typo in the message of your first (non-root) commit.

liyachao@ubuntu:~/git_hug$ git rebase -i HEAD~2

[detached HEAD c7e9f5d] First commit

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 file1

Successfully rebased and updated refs/heads/master.

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: squash

Level: 44

Difficulty: ****

You have committed several times but would like all those changes to be one commit.

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Take a look the `-i` flag of the rebase command.

liyachao@ubuntu:~/git_hug$ git rebase -i HEAD~3

[detached HEAD dfca21a] Updating README

1 file changed, 3 insertions(+)

Successfully rebased and updated refs/heads/master.

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: merge_squash

Level: 45

Difficulty: ***

Merge all commits from the long-feature-branch as a single commit.

liyachao@ubuntu:~/git_hug$ git branch

long-feature-branch

* master

liyachao@ubuntu:~/git_hug$ githug hint

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Take a look at the `--squash` option of the merge command. Don't forget to commit the merge!

liyachao@ubuntu:~/git_hug$ git merge --squash long-feature-branch

Squash commit -- not updating HEAD

Automatic merge went well; stopped before committing as requested

liyachao@ubuntu:~/git_hug$ git commit -m "all"

[master ec08d95] all

1 file changed, 3 insertions(+)

create mode 100644 file3

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: reorder

Level: 46

Difficulty: ****

You have committed several times but in the wrong order. Please reorder your commits.

lliyachao@ubuntu:~/git_hug$ git branch

* master

liyachao@ubuntu:~/git_hug$ git log

commit 774ad340e98c69888971e52e56caa1d32a07ed76

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:24:23 2014 +0800

Second commit

commit 878d074b102d92c44b667870339ab96f5b674732

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:24:23 2014 +0800

Third commit

commit 0ebf7932231cb93cb238d2803d3f626652aa9ed9

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:24:23 2014 +0800

First commit

commit 44853df7ac5b6a2c09994dc4637ed3b9d5a44260

Author: liyachao <296777513@qq.com>

Date:   Sat Oct 18 19:24:23 2014 +0800

liyachao@ubuntu:~/git_hug$ git rebase -i HEAD~3

Successfully rebased and updated refs/heads/master.

liyachao@ubuntu:~/git_hug$ githug

********************************************************************************

*                                    Githug                                    *

********************************************************************************

Congratulations, you have solved the level!

Name: bisect

Level: 47

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.

liyachao@ubuntu:~/git_hug$

githug通关部分黏贴(git代码练习)相关推荐

  1. 微软打造了全球最大的Git代码库

    丹棱君有话说:今年 2 月,微软宣布将用 Git 管理 Windows 源代码.随后,Visual Studio 宣布开发 "Git 虚拟文件系统(GVFS)",并将在终极项目和超 ...

  2. 程序员必须知道的几个Git代码托管平台(转)

    上一篇博客中2015继续任性--不会Git命令,照样玩转Git我们简单的介绍了在VS2013中使用Git,和GitHub客户端的使用.那么使用Git到底有什么好处呢?最为明显的是支持Git代码托管的平 ...

  3. git 代码托管使用方法

    Git代码托管 1 准备材料 在coding,github这些代码托管网站上申请一个账户. Linux平台什么需要一个git,如ubuntu 需要 $ sudo apt-get install git ...

  4. GIt代码托管、Github Desktop和 Pycharm中代码的管理

    5_GIt代码托管.Github Desktop和 Pycharm中代码的管理 1 Git代码托管 2 Github Desktop使用 3 Pycharm中代码管理 1 Pycharm中代码上传到g ...

  5. clone远程代码 在不同电脑上git_用树莓派3搭建私有git代码仓库

    0.出发点 由于项目开发的规模和复杂度越来越大,有时候需要同时多人在不同的嵌入式linux上开发代码,在没有用git管理代码和文档前,很难同步代码和文档的版本,宝贵的代码存储也没有安全感. githu ...

  6. git源码服务器搭建,树莓派3-搭建GIT代码服务器

    搭建GIT代码服务器 说明 利用树莓派为我所有的Git仓库创建了一个Git私有服务器,方便私有代码和文档的管理. 安装 安装Git服务器和必要的客户端软件 sudo apt-get install w ...

  7. Git代码同时push到GitHub和Gitee(码云)

    Git代码同时push到GitHub和Gitee(码云) 1. 在Gitee和GitHub上分别创建一个项目(同名项目) 2. 克隆项目到本地 //从gitee 获取 $ git clone http ...

  8. git 代码推送流程_Git 101:一个让您开始推送代码的Git工作流程

    git 代码推送流程 I'm going to explain Git the way I wish someone had explained to me back when I was first ...

  9. 国内2大Git代码托管网站

    可以说GitHub的出现完全颠覆了以往大家对代码托管网站的认识.GitHub不但是一个代码托管网站,更是一个程序员的SNS社区.GitHub真正迷人的是它的创新能力与Geek精神,这些都是无法模仿的. ...

最新文章

  1. 经典的C++面试题目
  2. tableau地图城市数据_Tableau 地图 | 无法识别的城市
  3. Git的安装与使用教程
  4. 中国象棋棋子及棋盘的绘制
  5. 做游戏,学编程(C语言) 18 瑞克快跑
  6. [经验]修改SDI主窗口Title
  7. ZOJ Monthly, March 2018 A Easy Number Game
  8. 用android编写计数器前后台源代码,在Android中实现计数器
  9. Delphi外挂制作
  10. [Matlab]使用textscan读取.csv文件时候只读取到了第一行
  11. 百度提交网站提示您无权访问该页面,点击确定按钮返回首页,如何解决
  12. Neuralizing Regular Expressions for Slot Filling 神经网络转回自动机
  13. 无线上外网,有线上内网的方式(转)
  14. [原创]Java Web——外卖配送系统/在线点餐系统
  15. Timing Constraint介绍-Design Compiler(三)
  16. 搜狗输入法低版本导致谷歌浏览器上传下载时崩溃
  17. 仿头条新闻资讯dz模板/Discuz新闻资讯商业版GBK模板
  18. 说说微信红包算法,为什么你总是抢的那么少?
  19. blender中python脚本使用
  20. python输入1到7输出星期_Python每日小知识(1):输入和输出、数据类型和变量

热门文章

  1. 链表(提高)-数据结构(二)
  2. 2022上海省赛(A,E,G,H,M,N)
  3. 十年阿里巴巴资深架构师整理分享的SpringSecurity实战文档
  4. 寒武纪裁员:软件研发部门和应届生为重灾区
  5. ETA4322耐压30V,线性充1000mA,充电电流可调,双灯指示
  6. redis主从、哨兵、集群
  7. Teamspeak3集成要注意的问题
  8. 为什么计算机集群叫云,为什么叫云计算?
  9. 【sass】Sass教程
  10. 域名解析暂时失败(二)