学习gitGit

通关git抱抱

2016-01-03  本文已影响166人  高冰洁

'githug'是一个跟'learnyournode'差不多的通关github,在浪费了一个可以看电影的下午,我把这个并没有什么卵用的东西写了写。你需要做的很简单:follow the instructions。首先check一下电脑上ruby的环境,然后直接安装

$ gem install githug

$githug

然后就能看见一个闯关的基本界面,在每次完成后记得问githug这样对不对就可以进行到下一关了。

Level 1: initialize an empty repository

$ git init

Level 2 Set up name and email

$ git config user.name "CatAmo10"

$ git config user.email CatAmo10@example.com

Level 3 add 'README' files in folder to staging area

$ git add README

或者一般情况下,当我merge出了错我会直接用

$ git add .

把所有untracked文件都加上

Level 4 Commit file

$ git commit -m "your own commit message"

一般如果说没有change,只是修改文件,我会用

$ git commit -am "your own commit message"

Level 5 Clone a repo

$ git clone https://github.com/Gazler/clonename

Level 6 clone to a folder

$ git clone https://github.com/Gazler/clonename my_cloned_repo

Level 7 ignore files

修改文件.gitirnore

$ vim .gitignore

在文件中加上

*.swp

忽略所有尾缀为'.swp'的文件

Level 8

和上一步操作一样,只需要忽略所有'.a'文件,并加上

!lib.a

Level 9 Status

$ git status

git status answer the githug question
Level 10

跟上一步还是一样的,查看一下status

Level 11 remove files

第一步,检查被remove的文件

$ git checkout

第二步

$ git rm deleteme.rb

Level 12 remove files added to staging ara which you do not want

$git rm --cached deleteme.rb

Level 13 save changes without commit

$ git stash

Level 14 rename file name

git mv oldfile.txt newfile.txt

Level 15 Restructure, move all the files

$ mkdir src

$ git mv *.html src

Level 16 log

$ git log

Level 17 tag

$ git tag new_tag

Level 18 push tags

$ git push --tags

Level 19 Commit amend

$ git add forgotten_file.rb

$ git commit --amend

Level 20 commit files with specific dates

$ git commit --date=03.01.2016T14:09:05

Level 21 reset

$ git reset HEAD to_commit_second.rb

Level 22 reset soft

如果放回working directory应该就要checkout这个file了,但是reset soft只是放回了staging area

$ git reset --soft HEAD^

Level 23 checkout files

$ git checkout config.rb

Level 24 remote

$ git remote

Level 25 remote url

$ git remote url

Level 26 pull changes

$ git pull origin master

Level 27 add a new remote

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

Level 28 rebase commit onto master

$ git rebase origin/master master
$ git push origin master

Level 29 diff

$ git diff

Level 30 blame

$ git blame config.rb

find the name to be blamed
Level 31 create a branch

$ git brahch test_code

Level 32 switch to another branch

$git branch mybranch

$ git checkout mybranch

Level 33 checkout a tag

$ git checkout v1.2

Level 34 checkout a tag with the same-name branch

$ git checkout tags/v1.2

Level 35 create a branch at previou commit

$ git branch test_branch HEAD^

Level 36 delete a branch

$ git branch -d delete_me

Level 37 push specific branch to remote

$ git push origin test_branch

Level 38 merge

$ git merge feature

Level 39 fetch

我觉得fetch和pull的区别在于,pull相当于fetch了之后再merge,所以此处应该有fetch

$ git fetch origin

LEvel 40 rebase

$ git rebase feature

$ git checkout feature

$ git rebase -i master

Level 41 repack

$ git repack

$ git repack -d

Level 42 cherry-pick

我第一次听到这么好听的命令,但是...我依旧没太明白这个优雅的命令有什么大用途,我简单的认为这是一种附有强烈处女情结的merge,只挑某个branch上的一个commit引入master而不是仅仅去merge两个分支。我猜想log会变得更好看一些。
首先要把那个看上去does not make any sense的长长的SHA码找到

$ git checkout new-feature

$ git log

$ git checkout master

$ git cherry-pick ca32a6d

Level 43 grep check TODOs

$ git grep TODO

Level 44 rename the commit

again、还是要check一下log

$ git log

复制第一个commit地址

$ git rebase i ffc13cc

现在你能看到文件中几个命令,文件是按照命令顺序自上而下运行,所以只要在第一句前面加上reword就行了

Level 45 merge multiple commit to one

还记得上一步中的文件中有一个命令叫做squash吗?对squash标准解释是受挤压,就是简单地把几次commit挤压成一次

$ git log

$ git rebase i

把最终输出的那唯一一个commit留着,其他均改成squash

Level 46 merge squash, merge all commits

$ git merge --squash long-feature-branch

Level 47 reorder

$ git rebase i 85d671

记得check一下log,然后直接修改文件的命令顺序,自上而下

Level 48 bisect

$ git bisect start

如果这个时候直接 'git bisect run make test'就会跳出帮助,必须有set bad或者good之后才能run test

ruby prog.rb 5

git bisect bad

$ git log

$ git checkout 5db7a7c

ruby prog.rb 5

git bisect good
...

总之一直循环到可以运行

$ git bisect run make test

Level 49 stage one file in first feature

$ git add -p

然后选择'n',手动修改,直接将second feature删掉

Level 50 find an old branch

$ git reflog

$ git checkout solve_world_hunger

Level 51 revert, redo middle commit not changing existing history

$ git revert HEAD^1

Level 52 restore a deteleted commit

$ git log

$ git checkout 3d5de5f

Level 53 conflict

$ git merge mybranch

发现在poem.txt中又conflict,所以现在需要修改文件poem.txt

$ vim poem.txt

为以防万一,再加上所有untracked文件

$ git add .

$ git commit

$ git merge mybranch

Level 54 submodule

git submodule https://github.com/jackmoney/githug-include-me ./githug-include-me

当到这一步的时候就结束了,你需要做的就是fork这个github项目,并加上一些自己的Level

上一篇 下一篇

猜你喜欢

热点阅读