原文: 通關(guān)Githug(二)
date: 2017-12-25 12:39:05
[TOC]
繼續(xù)上一篇通關(guān)Githug(一)
關(guān)卡列表
再附上30-55關(guān)目錄
關(guān)卡名稱 | 學(xué)習(xí)內(nèi)容 | Git 命令 |
第30關(guān) blame | 查詢每一行代碼被誰(shuí)編輯過(guò) | git blame |
第31關(guān) branch | 創(chuàng)建分支 | git branch |
第32關(guān) checkout | 切換分支 | git checkout |
第33關(guān) checkout_tag | 切換到標(biāo)簽 | git checkout |
第34關(guān) checkout_tag_over_branch | 切換到標(biāo)簽 | git checkout |
第35關(guān) branch_at | 在指定的提交處創(chuàng)建分支 | git branch |
第36關(guān) delete_branch | 刪除分支 | git branch -d |
第37關(guān) push_branch | 推送分支到遠(yuǎn)程倉(cāng)庫(kù) | git push |
第38關(guān) merge | 合并分支 | git merge |
第39關(guān) fetch | 從遠(yuǎn)程倉(cāng)庫(kù)抓取數(shù)據(jù) | git fetch |
第40關(guān) rebase | 變基合并 | git rebase |
第41關(guān) repack | 重新打包 | git repack |
第42關(guān) cherry-pick | 合并分支上指定的提交 | git cherry-pick |
第43關(guān) grep | 搜索文本 | git grep |
第44關(guān) rename_commit | 修改歷史提交的說(shuō)明 | git rebase -i |
第45關(guān) squash | 把多次提交合并成一次提交 | git rebase -i |
第46關(guān) merge_squash | 合并分支時(shí)把多次提交合并成一次提交 | git merge –squash |
第47關(guān) reorder | 調(diào)整提交順序 | git rebase -i |
第48關(guān) bisect | 用二分法定位 bug | git bisect |
第49關(guān) stage_lines | 添加文件的部分行到暫存區(qū) | git add –edit |
第50關(guān) file_old_branch | 查看 Git 上的操作歷史 | git reflog |
第51關(guān) revert | 取消已推送到遠(yuǎn)程倉(cāng)庫(kù)的提交 | git revert |
第52關(guān) restore | 恢復(fù)被刪除的提交 | git reset –hard |
第53關(guān) conflict | 解決沖突 | |
第54關(guān) submodule | 把第三方庫(kù)當(dāng)作子模塊 | git submodule |
第55關(guān) contribute | 捐獻(xiàn) |
Level 30: blame
Someone has put a password inside the file ‘config.rb’ find out who it was.
有人在config.rb文件里放了個(gè)password, 找出來(lái)誰(shuí)搞的?
[root@pipeline-cloud-test02 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, :password
97bdd0cc (Spider Man 2012-03-08 23:08:15 +0000 3) def initialize(name, password = nil, options = {})
^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 || "i<3evil"
00000000 (Not Committed Yet 2017-12-22 16:23:59 +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
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Who made the commit with the password? Spider Man
Congratulations, you have solved the level!
這個(gè)命令會(huì)詳細(xì)列出該文件每行代碼提交的哈希值, 提交的人和日期
Level 31: branch
You want to work on a piece of code that has the potential to break things, create the branch test_code.
你想實(shí)驗(yàn)一些代碼, 但害怕有問(wèn)題. 創(chuàng)建一個(gè)新分支test_code
[root@pipeline-cloud-test02 git_hug]# git branch test_code
[root@pipeline-cloud-test02 git_hug]# git branch
* master
test_code
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
git branch xxx # 創(chuàng)建一個(gè)分支
git branch # 列出所有分支
Level 32: checkout
Create and switch to a new branch called my_branch. You will need to create a branch like you did in the previous level.
創(chuàng)建一個(gè)新分支my_branch并切換到這個(gè)新分支
[root@pipeline-cloud-test02 git_hug]# git branch my_branch
[root@pipeline-cloud-test02 git_hug]# git checkout my_branch
Switched to branch 'my_branch'
[root@pipeline-cloud-test02 git_hug]# git branch
master
* my_branch
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
補(bǔ)充:
git checkout xxxBranch # 檢出一個(gè)分支
git checkout xxxFile # 之前講過(guò)如何撤銷進(jìn)入暫存區(qū)的修改, 這個(gè)也可以
git checkout -b xxx # == git branch xxx + git checkout xxx
git checkout - # 用于在最近的兩個(gè)分支之間切換
Level 33: checkout_tag
You need to fix a bug in the version 1.2 of your app. Checkout the tag
v1.2
.你需要切換到
tag v1.2
上去修復(fù)一些Bug
[root@pipeline-cloud-test02 git_hug]# git branch
* master
[root@pipeline-cloud-test02 git_hug]# git tag
v1.0
v1.2
v1.5
[root@pipeline-cloud-test02 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 060320d... Some more changes
[root@pipeline-cloud-test02 git_hug]# git branch
* (detached from v1.2)
master
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
注意: 從前面已經(jīng)看到git checkout
后面可以跟分之, 標(biāo)簽, 文件. 但是作用不通.
Level 34: checkout_tag_over_branch
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 namedv1.2
).切換到
tag v1.2
上去修復(fù)一個(gè)bug(注意有一個(gè)分支也叫v1.2)
[root@pipeline-cloud-test02 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 fc5edda... Some more changes
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
這樣區(qū)分就好了.
Level 35: branch_at
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.
你忘記在上次提交之前先創(chuàng)建一個(gè)分支, 那么創(chuàng)建一個(gè)test_branch在上次提交之前
[root@pipeline-cloud-test02 git_hug]# git log --oneline
03a7f2c Updating file1 again
3bcda78 Updating file1
3873d24 Adding file1
[root@pipeline-cloud-test02 git_hug]# git branch test_branch 3bcda78
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 36: delete_branch
You have created too many branches for your project. There is an old branch in your repo called ‘delete_me’, you should delete it.
刪掉
delete_me
分支
[root@pipeline-cloud-test02 git_hug]# git branch
delete_me
* master
[root@pipeline-cloud-test02 git_hug]# git branch -d delete_me
Deleted branch delete_me (was b60afe2).
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 37: push_branch
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.
你本地分支做了些修改想分享它, 但是不準(zhǔn)備合并到master上. 所以把他推送到test_branch分支遠(yuǎn)程倉(cāng)庫(kù)上.
[root@pipeline-cloud-test02 git_hug]# git remote
origin
[root@pipeline-cloud-test02 git_hug]# git branch
* master
other_branch
test_branch
[root@pipeline-cloud-test02 git_hug]# git push origin test_branch
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 572 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
To /tmp/d20171222-302-aokpd0/.git
* [new branch] test_branch -> test_branch
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 38: merge
We have a file in the branch ‘feature’; Let’s merge it to the master branch.
feature分支上有個(gè)文件, 把它合并到master上
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
e12277f added file1
[root@pipeline-cloud-test02 git_hug]# git log feature --oneline
cc8ea5a added file2
e12277f added file1
[root@pipeline-cloud-test02 git_hug]# git branch
feature
* master
[root@pipeline-cloud-test02 git_hug]# git merge feature
Updating e12277f..cc8ea5a
Fast-forward
file2 | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file2
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
cc8ea5a added file2
e12277f added file1
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
分支測(cè)試完成后就可以合并到主干, 主干上也會(huì)記錄對(duì)應(yīng)的日志.
Level 39: fetch
Looks like a new branch was pushed into our remote repository. Get the changes without merging them with the local repository
有一個(gè)新的分支推送到遠(yuǎn)程倉(cāng)庫(kù)了, 得到它但是不要合并到你的本地倉(cāng)庫(kù)
[root@pipeline-cloud-test02 git_hug]# git branch
* master
[root@pipeline-cloud-test02 git_hug]# git branch -r
origin/master
[root@pipeline-cloud-test02 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/d20171222-797-1165a5c/
* [new branch] new_branch -> origin/new_branch
[root@pipeline-cloud-test02 git_hug]# git branch
* master
[root@pipeline-cloud-test02 git_hug]# git branch -r
origin/master
origin/new_branch
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
為什么不用git pull
呢, 因?yàn)樗粌H會(huì)拉取遠(yuǎn)程代碼, 還會(huì)合并到本地代碼, 相當(dāng)于git fetch
+git merge
在 git fetch
之后用 git branch -r
查看時(shí)會(huì)發(fā)現(xiàn)新分支的名稱
Level 40: rebase
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.
我們使用了git rebase工作流, 并準(zhǔn)備把feature分支合并到master. 現(xiàn)在rebase feature分支到master分之上吧.
[root@pipeline-cloud-test02 git_hug]# git branch
feature
* master
[root@pipeline-cloud-test02 git_hug]# git checkout feature
Switched to branch 'feature'
[root@pipeline-cloud-test02 git_hug]# git log --oneline
ed0fdcf add feature
a78bcab init commit
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
98205e9 add content
a78bcab init commit
[root@pipeline-cloud-test02 git_hug]# git rebase master
First, rewinding head to replay your work on top of it...
Applying: add feature
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
98205e9 add content
a78bcab init commit
[root@pipeline-cloud-test02 git_hug]# git log --oneline
967920c add feature
98205e9 add content
a78bcab init commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
參考: Git Rebase原理以及黃金準(zhǔn)則詳解
Level 41: rebase_onto
You have created your branch from
wrong_branch
and already made some commits, and you realise that you needed to create your branch frommaster
. Rebase your commits ontomaster
branch so that you don’t havewrong_branch
commits.你錯(cuò)誤的從
wrong_branch
上創(chuàng)建了一個(gè)分支, 并且有了一些提交, 但是你意識(shí)到你應(yīng)該是從master
上創(chuàng)建分支, 現(xiàn)在rebase你的提交到master
分支上去, 并且不保留wrong_branch
的提交.
[root@pipeline-cloud-test02 git_hug]# git branch
master
* readme-update
wrong_branch
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
3d8ad8d Create authors file
[root@pipeline-cloud-test02 git_hug]# git log wrong_branch --oneline
a2c5c42 Wrong changes
3d8ad8d Create authors file
[root@pipeline-cloud-test02 git_hug]# git log --oneline
9c959f1 Add `Install` header in readme
082624b Add `About` header in readme
73dbf72 Add app name in readme
a2c5c42 Wrong changes
3d8ad8d Create authors file
[root@pipeline-cloud-test02 git_hug]# git rebase --onto master wrong_branch readme-update
First, rewinding head to replay your work on top of it...
Applying: Add app name in readme
Applying: Add `About` header in readme
Applying: Add `Install` header in readme
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
3d8ad8d Create authors file
[root@pipeline-cloud-test02 git_hug]# git log wrong_branch --oneline
a2c5c42 Wrong changes
3d8ad8d Create authors file
[root@pipeline-cloud-test02 git_hug]# git log --oneline
b113760 Add `Install` header in readme
809fc39 Add `About` header in readme
7adf9cd Add app name in readme
3d8ad8d Create authors file
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
wrong_branch
和master
分支的日志都沒(méi)有變, 注意看readme-update
的日志變化.
補(bǔ)充:
摘一段官網(wǎng)的內(nèi)容:
First let’s assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next.
o---o---o---o---o master
\
o---o---o---o---o next
\
o---o---o topic
We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master branch. We want our tree to look like this:
o---o---o---o---o master
| \
| o'--o'--o' topic
\
o---o---o---o---o next
We can get this using the following command:
git rebase –onto master next topic
Level 42: repack
Optimise how your repository is packaged ensuring that redundant packs are removed.
優(yōu)化倉(cāng)庫(kù)的打包, 確保刪除掉重復(fù)多余的包
[root@pipeline-cloud-test02 git_hug]# ls .git/objects/
4d 80 e6 info pack
[root@pipeline-cloud-test02 git_hug]# git repack -d
Counting objects: 3, done.
Writing objects: 100% (3/3), done.
Total 3 (delta 0), reused 0 (delta 0)
[root@pipeline-cloud-test02 git_hug]# ls .git/objects/
info pack
[root@pipeline-cloud-test02 git_hug]# ls .git/objects/pack/
pack-830ef7487354a6468143f53dd19ee16c25fc2837.idx pack-830ef7487354a6468143f53dd19ee16c25fc2837.pack
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 43: cherry-pick
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.你的新功能廢了你要?jiǎng)h除它! 但是其中有一次README的提交還是有用的, 你把這次提交合并到主干上.
[root@pipeline-cloud-test02 git_hug]# git branch
* master
new-feature
[root@pipeline-cloud-test02 git_hug]# git log new-feature --oneline
ea2a47c some small fixes
4a1961b Fixed feature
ca32a6d Filled in README.md with proper input
58a8c8e Added a stub for the feature
ea3dbcc Initial commit
[root@pipeline-cloud-test02 git_hug]# git log --oneline
6edea63 Added fancy branded output
232d266 Renamed project.js -> herdcore-math.js
b30c6a9 Added a hardcore math module
ea3dbcc Initial commit
[root@pipeline-cloud-test02 git_hug]# git cherry
cherry cherry-pick
[root@pipeline-cloud-test02 git_hug]# git cherry
cherry cherry-pick
[root@pipeline-cloud-test02 git_hug]# git cherry-pick ca32a6d
[master 25034ea] Filled in README.md with proper input
Author: Andrey <aslushnikov@gmail.com>
1 file changed, 1 insertion(+), 2 deletions(-)
[root@pipeline-cloud-test02 git_hug]# git log --oneline
25034ea Filled in README.md with proper input
6edea63 Added fancy branded output
232d266 Renamed project.js -> herdcore-math.js
b30c6a9 Added a hardcore math module
ea3dbcc Initial commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
git cherry-pick hash-code
: 摘櫻桃. 可以選取一個(gè)分支上某次提交的哈希值來(lái)合并到主線上.
Level 44: grep
Your project’s deadline approaches, you should evaluate how many TODOs are left in your code.
找下項(xiàng)目里還有多少待辦事項(xiàng)(TODOs)
[root@pipeline-cloud-test02 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.
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
How many items are there in your todolist? 4
Congratulations, you have solved the level!
git grep xxx # 全項(xiàng)目查找
git grep xxx file-name # 指定文件查找
Level 45: rename_commit
Correct the typo in the message of your first (non-root) commit.
修正第一次提交的拼寫錯(cuò)誤
[root@pipeline-cloud-test02 git_hug]# git log --oneline
5da15a1 Second commit
d1c06bd First coommit
2b08caa Initial commit
[root@pipeline-cloud-test02 git_hug]# git rebase -i 2b08caa
[detached HEAD ac4092f] First commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file1
Successfully rebased and updated refs/heads/master.
[root@pipeline-cloud-test02 git_hug]# git log --oneline
208de39 Second commit
ac4092f First commit
2b08caa Initial commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
補(bǔ)充:
git rebase -i hash-code
:
后面加了-i
參數(shù)后就不再是分支合并的意思了. -i
表示交互, 后面跟上提交的哈希碼, 可以修改歷史的提交.
執(zhí)行該命令后, 會(huì)啟動(dòng)文本編輯器, 并在其中顯示每次提交的記錄信息(從前到后顯示).
每行記錄前面會(huì)有一個(gè)標(biāo)識(shí), 表示進(jìn)行什么修改操作:
Commands:
- p, pick: 表示執(zhí)行此次提交
- r, reword: 表示執(zhí)行此次提交鸣奔,但要修改備注內(nèi)容
- e, edit: 表示可以修改此次提交赖草,比如再追加文件或修改文件
- s, squash : 表示把此次提交的內(nèi)容合并到上次提交中可柿,備注內(nèi)容也合并到上次提交中
- f, fixup : 和 “squash” 類似辆脸,但會(huì)丟棄掉此次備注內(nèi)容
- x, exec : 執(zhí)行命令行下的命令
- drop : 刪除此次提交
本關(guān)用的就是reword.
Level 46: squash
You have committed several times but would like all those changes to be one commit.
把多次提交合并成一次
[root@pipeline-cloud-test02 git_hug]# git log --oneline
a68644a Updating README (squash this commit into Adding README)
712a031 Updating README (squash this commit into Adding README)
da9df2a Updating README (squash this commit into Adding README)
e799cb3 Adding README
04a03cf Initial Commit
[root@pipeline-cloud-test02 git_hug]# git rebase -i 04a03cf
[detached HEAD 63c098c] Adding README
1 file changed, 3 insertions(+)
create mode 100644 README
Successfully rebased and updated refs/heads/master.
[root@pipeline-cloud-test02 git_hug]# git log --oneline
63c098c Adding README
04a03cf Initial Commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
本關(guān)用的就是squash.
Level 47: merge_squash
Merge all commits from the long-feature-branch as a single commit.
把
long-feature-branch
上的多次提交合并到主干上的一次提交
[root@pipeline-cloud-test02 git_hug]# git branch
long-feature-branch
* master
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
b79bd86 Second commit
24289dd First commit
[root@pipeline-cloud-test02 git_hug]# git log long-feature-branch --oneline
0a1ccc1 Time
36fb820 Takes
cef0b75 Developing new features
24289dd First commit
[root@pipeline-cloud-test02 git_hug]# git merge long-feature-branch --squash
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
[root@pipeline-cloud-test02 git_hug]# git commit -m "merge from long-fxxxx-branch"
[master 18b8931] merge from long-fxxxx-branch
1 file changed, 3 insertions(+)
create mode 100644 file3
[root@pipeline-cloud-test02 git_hug]# git log master --oneline
18b8931 merge from long-fxxxx-branch
b79bd86 Second commit
24289dd First commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
通常分支上會(huì)有很多個(gè)提交, 在合并到主干上時(shí)也會(huì)給主干帶過(guò)去多次提交記錄, 這樣不便于追蹤.
所以使用git merge xxbranch_name --squash
命令把分支的多次提交搞成一次.
注意使用完合并之后, 需要在commit
一下, 并寫上注釋信息. (不加--squash
時(shí)會(huì)自動(dòng)commit).
Level 48: reorder
You have committed several times but in the wrong order. Please reorder your commits.
調(diào)整提交順序
[root@pipeline-cloud-test02 git_hug]# git log --oneline
ef9e60e Second commit
54c5e74 Third commit
b424f5a First commit
b435e3c Initial Setup
[root@pipeline-cloud-test02 git_hug]# git rebase -i b435e3c
Successfully rebased and updated refs/heads/master.
[root@pipeline-cloud-test02 git_hug]# git log --oneline
94b9586 Third commit
866d552 Second commit
b424f5a First commit
b435e3c Initial Setup
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 49: bisect
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.
在開(kāi)發(fā)過(guò)程中引入了一個(gè) bug。已知運(yùn)行 “ruby prog.rb 5” 應(yīng)該輸入 15蜗巧,你也可以運(yùn)行 “make test” 進(jìn)行測(cè)試芯咧。你需要確定引入 bug 的那次提交的哈希值的前7位。
[root@pipeline-cloud-test02 git_hug]# git log --oneline
12628f4 Another Commit
9795761 Another Commit
028763b Another Commit
888386c Another Commit
bb736dd Another Commit
18ed2ac Another Commit
5db7a7c Another Commit
7c03a99 Another Commit
9f54462 Another Commit
5d1eb75 Another Commit
fdbfc0d Another Commit
a530e7e Another Commit
ccddb96 Another Commit
2e1735d Another Commit
ffb097e Another Commit
e060c0d Another Commit
49774ea Another Commit
8c992af Another Commit
80a9b3d Another Commit
f608824 First commit
[root@pipeline-cloud-test02 git_hug]# git bisect start
[root@pipeline-cloud-test02 git_hug]# git bisect good f608824
[root@pipeline-cloud-test02 git_hug]# git bisect bad 12628f4
Bisecting: 9 revisions left to test after this (roughly 3 steps)
[fdbfc0d403e5ac0b2659cbfa2cbb061fcca0dc2a] Another Commit
[root@pipeline-cloud-test02 git_hug]# make test
ruby prog.rb 5 | ruby test.rb
[root@pipeline-cloud-test02 git_hug]# git bisect good
Bisecting: 4 revisions left to test after this (roughly 2 steps)
[18ed2ac1522a014412d4303ce7c8db39becab076] Another Commit
[root@pipeline-cloud-test02 git_hug]# make test
ruby prog.rb 5 | ruby test.rb
make: *** [test] Error 1
[root@pipeline-cloud-test02 git_hug]# git bisect bad
Bisecting: 2 revisions left to test after this (roughly 1 step)
[9f54462abbb991b167532929b34118113aa6c52e] Another Commit
[root@pipeline-cloud-test02 git_hug]# make test
ruby prog.rb 5 | ruby test.rb
[root@pipeline-cloud-test02 git_hug]# git bisect good
Bisecting: 0 revisions left to test after this (roughly 1 step)
[5db7a7cb90e745e2c9dbdd84810ccc7d91d92e72] Another Commit
[root@pipeline-cloud-test02 git_hug]# make test
ruby prog.rb 5 | ruby test.rb
[root@pipeline-cloud-test02 git_hug]# git bisect good
18ed2ac1522a014412d4303ce7c8db39becab076 is the first bad commit
commit 18ed2ac1522a014412d4303ce7c8db39becab076
Author: Robert Bittle <guywithnose@gmail.com>
Date: Mon Apr 23 06:52:10 2012 -0400
Another Commit
:100644 100644 917e70054c8f4a4a79a8e805c0e1601b455ad236 7562257b8e6446686ffc43a2386c50c254365020 M prog.rb
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
What are the first 7 characters of the hash of the commit that introduced the bug? 18ed2ac1522a014412d4303ce7c8db39becab076
Congratulations, you have solved the level!
對(duì)我沒(méi)用.. 略
Level 50: stage_lines
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.
一個(gè)文件里有兩個(gè)功能, 現(xiàn)在只想把其中一個(gè)功能提交到暫存區(qū).
[root@pipeline-cloud-test02 git_hug]# git status -s
M feature.rb
[root@pipeline-cloud-test02 git_hug]# git diff feature.rb
diff --git a/feature.rb b/feature.rb
index 1a271e9..4a80dda 100644
--- a/feature.rb
+++ b/feature.rb
@@ -1 +1,3 @@
this is the class of my feature
+This change belongs to the first feature
+This change belongs to the second feature
[root@pipeline-cloud-test02 git_hug]# git add feature.rb --edit
[root@pipeline-cloud-test02 git_hug]# git status -s
MM feature.rb
[root@pipeline-cloud-test02 git_hug]# git diff feature.rb
diff --git a/feature.rb b/feature.rb
index 3bccd0e..4a80dda 100644
--- a/feature.rb
+++ b/feature.rb
@@ -1,2 +1,3 @@
this is the class of my feature
This change belongs to the first feature
+This change belongs to the second feature
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
git add file_name --edit
會(huì)在添加文件時(shí)打開(kāi)編輯器, 并顯示文件diff結(jié)果. 可以根據(jù)編輯的結(jié)果進(jìn)行add操作.
Level 51: find_old_branch
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.
你忘了剛才時(shí)在哪個(gè)分支上工作了, 找到它. 切換過(guò)去
[root@pipeline-cloud-test02 git_hug]# git reflog
894a16d HEAD@{0}: commit: commit another todo
6876e5b HEAD@{1}: checkout: moving from solve_world_hunger to kill_the_batman
324336a HEAD@{2}: commit: commit todo
6876e5b HEAD@{3}: checkout: moving from blowup_sun_for_ransom to solve_world_hunger
6876e5b HEAD@{4}: checkout: moving from kill_the_batman to blowup_sun_for_ransom
6876e5b HEAD@{5}: checkout: moving from cure_common_cold to kill_the_batman
6876e5b HEAD@{6}: commit (initial): initial commit
[root@pipeline-cloud-test02 git_hug]# git checkout solve_world_hunger
Switched to branch 'solve_world_hunger'
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
git reflog
不光記錄了Commit信息, 還記錄了分支切換的信息.
Level 52: revert
You have committed several times but want to undo the middle commit. All commits have been pushed, so you can’t change existing history.
你提交了很多次, 而且已經(jīng)推送到服務(wù)器上了,所以你不能改變已經(jīng)存在的歷史. 你想取消中間的某次提交.
[root@pipeline-cloud-test02 git_hug]# git log --oneline
498b9be Second commit
5a42119 Bad commit
4d925f6 First commit
[root@pipeline-cloud-test02 git_hug]# git revert 5a42119 --no-edit
[master c608236] Revert "Bad commit"
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 file3
[root@pipeline-cloud-test02 git_hug]# git log --oneline
c608236 Revert "Bad commit"
498b9be Second commit
5a42119 Bad commit
4d925f6 First commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
既然不能改變歷史, 那就用git revert
增加一次取消的逆處理.
git revert hash-code # 調(diào)用文本編輯器讓你編寫注釋
git revert hash-code --no-edit # 自動(dòng)生成注釋
Level 53: restore
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.你用
git reset --hard HEAD^
刪掉了最后一次提交(傻), 然后你改變主意了, 想回退恢復(fù)那條被刪除的提交.
[root@pipeline-cloud-test02 git_hug]# git log --oneline
d56c44f First commit
9fd667b Initial commit
[root@pipeline-cloud-test02 git_hug]# git reflog
d56c44f HEAD@{0}: reset: moving to HEAD^
dfabe57 HEAD@{1}: commit: Restore this commit
d56c44f HEAD@{2}: commit: First commit
9fd667b HEAD@{3}: commit (initial): Initial commit
[root@pipeline-cloud-test02 git_hug]# git reset --hard dfabe57
HEAD is now at dfabe57 Restore this commit
[root@pipeline-cloud-test02 git_hug]# git log --oneline
dfabe57 Restore this commit
d56c44f First commit
9fd667b Initial commit
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 54: conflict
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.
你要合并mybranch分支到當(dāng)前分支master, 可能有沖突, 解決!
[root@pipeline-cloud-test02 git_hug]# git merge mybranch
Auto-merging poem.txt
CONFLICT (content): Merge conflict in poem.txt
Automatic merge failed; fix conflicts and then commit the result.
[root@pipeline-cloud-test02 git_hug]# vim poem.txt
[root@pipeline-cloud-test02 git_hug]# git status
# On branch master
# You have unmerged paths.
# (fix conflicts and run "git commit")
#
# Unmerged paths:
# (use "git add <file>..." to mark resolution)
#
# both modified: poem.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@pipeline-cloud-test02 git_hug]# git add poem.txt
[root@pipeline-cloud-test02 git_hug]# git commit -m "merge mybranch to master"
[master 7c3ba83] merge mybranch to master
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 55: submodule
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.你想把
https://github.com/jackmaney/githug-include-me
這個(gè)倉(cāng)庫(kù)的代碼引入到自己項(xiàng)目的./githug-include-me
目錄胡野,這個(gè)方法不需要克隆第三方倉(cāng)庫(kù)材失,也不需要把第三方倉(cāng)庫(kù)的文件復(fù)制到你的項(xiàng)目中。
[root@pipeline-cloud-test02 git_hug]# git submodule add https://github.com/jackmaney/githug-include-me
Cloning into 'githug-include-me'...
remote: Counting objects: 9, done.
remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 9
Unpacking objects: 100% (9/9), done.
[root@pipeline-cloud-test02 git_hug]# githug
********************************************************************************
* Githug *
********************************************************************************
Congratulations, you have solved the level!
Level 56: contribute
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.
最后一關(guān), 是讓你去GitHub貢獻(xiàn)一個(gè)request.
其實(shí)到這已經(jīng)全部通關(guān)!