git rebase -i 修改提交
教程3 改寫提交!
6. 用rebase -i 修改提交
為了節(jié)省時(shí)間,這個(gè)教程使用現(xiàn)有的歷史記錄作為本地?cái)?shù)據(jù)庫(kù)。
從這里下載
我們進(jìn)入stepup-tutorial/tutorial6目錄。本地端的歷史記錄的狀態(tài)如下圖顯示。我們?cè)谶@里修改「添加commit的講解」的內(nèi)容。
用rebase -i ,首先選擇要修改的提交。
$ git rebase -i HEAD~~打開文本編輯器,將看到從HEAD到HEAD~~的提交如下圖顯示。
pick 9a54fd4 添加commit的說(shuō)明 pick 0d4a808 添加pull的說(shuō)明# Rebase 326fc9f..0d4a808 onto d286baa # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #將第一行的“pick”改成“edit”,然后保存并退出。將會(huì)顯示以下內(nèi)容,修改過(guò)的提交呈現(xiàn)退出狀態(tài)。
Stopped at d286baa... 添加commit的說(shuō)明 You can amend the commit now, withgit commit --amendOnce you are satisfied with your changes, rungit rebase --continue打開sample.txt,適當(dāng)?shù)匦薷摹癱ommit的講解”部分。
連猴子都懂的Git命令 add 把變更錄入到索引中 commit 記錄索引的狀態(tài) pull 取得遠(yuǎn)端數(shù)據(jù)庫(kù)的內(nèi)容用commit?--amend保存修改。
$ git add sample.txt $ git commit --amend現(xiàn)在已經(jīng)commit,但是rebase操作還沒結(jié)束。若要通知這個(gè)提交的操作已經(jīng)結(jié)束,請(qǐng)指定?--continue選項(xiàng)執(zhí)行rebase。
$ git rebase --continue這時(shí),有可能其他提交會(huì)發(fā)生沖突, 請(qǐng)修改沖突部分后再執(zhí)行add和rebase?--continue。這時(shí)不需要提交。如果在中途要停止rebase操作,請(qǐng)?jiān)趓ebase指定--abort選項(xiàng)執(zhí)行,這樣就可以抹去并停止在rebase的操作。
提交的修改完成了。如果要把多個(gè)提交修改成edit,下一個(gè)要修改的提交會(huì)退出,請(qǐng)執(zhí)行同樣的修改。
實(shí)際上,在rebase之前的提交會(huì)以O(shè)RIG_HEAD之名存留。如果rebase之后無(wú)法復(fù)原到原先的狀態(tài),可以用git reset --hard ORIG_HEAD復(fù)原到rebase之前的狀態(tài)。
from:?http://backlogtool.com/git-guide/cn/stepup/stepup7_6.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的git rebase -i 修改提交的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: git rebase -i 汇合提交
- 下一篇: git merge --squash改写