鍍金池/ 教程/ Java/ 第47關 reorder
第13關 stash
第37關 push_branch
附錄A Git 學習資源
第54關 submodule
第15關 restructure
第18關 push_tags
第17關 tag
前言
第22關 reset_soft
Githug 安裝和使用方法
第41關 repack
第16關 log
第7關 ignore
第10關 number_of_files_committed
第29關 diff
第1關 init
第4關 commit
第33關 checkout_tag
第20關 commit_in_future
第14關 rename
第39關 fetch
第9關 status
第11關 rm
第27關 remote_add
第3關 add
第24關 remote
第26關 pull
第44關 rename_commit
第23關 checkout_file
第32關 checkout
第55關 contribute
第47關 reorder
關卡列表
第35關 branch_at
第5關 clone
第45關 squash
第43關 grep
第36關 delete_branch
第53關 conflict
第34關 checkout_tag_over_branch
第42關 cherry-pick
第19關 commit_amend
Githug 通關攻略
附錄C Vim 常用命令
第48關 bisect
第46關 merge_squash
第2關 config
附錄B Linux 常用命令
第21關 reset
第50關 find_old_branch
第12關 rm_cached
第8關 include
第31關 branch
第49關 stage_lines
第30關 blame
第52關 restore
第51關 revert
第28關 push
第25關 remote_url
第40關 rebase
第38關 merge
第6關 clone_to_folder

第47關 reorder

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

你提交過幾次,但是提交的順序錯了,請調(diào)整提交順序。

在第44關和第45關我們使用 git rebase -i 命令修改了歷史日志的提交說明、把多次提交合并成了一次,在本關,我們要用這個命令來調(diào)整提交順序。

先查一下提交日志:

$ git log --pretty=oneline
3baec3ba260f841e097675e4ae6661a86e3dba50 Second commit
a5f696b57d524c83b9fbb094b013590e4ff3d43d Third commit
19f3b096c2765ab79d9b07a5bed3a4ebb83ebf6a First commit
f0c159847ae93dabc8fd23766b40cf0cc21b315d Initial Setup

從上面的查詢結果看出,"Second commit" 和 "Third commit" 的次序顛倒了。我們找到最后一條日志的哈希值 "f0c159847ae93",然后輸入下面的命令:

$ git rebase -i f0c159847ae93

系統(tǒng)自動打開文本編輯器,顯示出了歷史日志:

pick 19f3b09 First commit
pick a5f696b Third commit
pick 3baec3b Second commit

把第2行和第3行的內(nèi)容調(diào)整一下順序,即這樣:

pick 19f3b09 First commit
pick 3baec3b Second commit
pick a5f696b Third commit

然后保存退出,系統(tǒng)就會按照調(diào)整過的順序重新執(zhí)行一遍提交操作。再查看日志,發(fā)現(xiàn)順序已經(jīng)調(diào)整好了。

$ git log --pretty=oneline
58fe3005755a19d18c017973517dfaca1b1ae648 Third commit
e0e8d4428578fb7b1284b1c7902e435e9bd571c4 Second commit
19f3b096c2765ab79d9b07a5bed3a4ebb83ebf6a First commit
f0c159847ae93dabc8fd23766b40cf0cc21b315d Initial Setup

第47關過關畫面如下:

http://wiki.jikexueyuan.com/project/githug-walkthrough/images/level-47-reorder.png" alt="第47關 reorder" />