git rebase -i 修改提交_git

來源:互聯網
上載者:User

教程3 改寫提交。 6. 用rebase -i 修改提交

為了節省時間,這個教程使用現有的記錄作為本機資料庫。

從這裡下載

我們進入stepup-tutorial/tutorial6目錄。本地端的記錄的狀態如下圖顯示。我們在這裡修改「添加commit的講解」的內容。

用rebase -i ,首先選擇要修改的提交。

$ git rebase -i HEAD~~

開啟文字編輯器,將看到從HEAD到HEAD~~的提交如下圖顯示。

pick 9a54fd4 添加commit的說明pick 0d4a808 添加pull的說明# 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”,然後儲存並退出。將會顯示以下內容,修改過的提交呈現退出狀態。

Stopped at d286baa... 添加commit的說明You can amend the commit now, with        git commit --amendOnce you are satisfied with your changes, run        git rebase --continue

開啟sample.txt,適當地修改“commit的講解”部分。

連猴子都懂的Git命令add 把變更錄入到索引中commit 記錄索引的狀態pull 取得遠端資料庫的內容

用commit --amend儲存修改。

$ git add sample.txt$ git commit --amend

現在已經commit,但是rebase操作還沒結束。若要通知這個提交的操作已經結束,請指定 --continue選項執行rebase。

$ git rebase --continue

Note

這時,有可能其他提交會發生衝突, 請修改衝突部分後再執行add和rebase --continue。這時不需要提交。如果在中途要停止rebase操作,請在rebase指定--abort選項執行,這樣就可以抹去並停止在rebase的操作。

提交的修改完成了。如果要把多個提交修改成edit,下一個要修改的提交會退出,請執行同樣的修改。

Note

實際上,在rebase之前的提交會以ORIG_HEAD之名存留。如果rebase之後無法複原到原先的狀態,可以用git reset --hard ORIG_HEAD複原到rebase之前的狀態。


from: http://backlogtool.com/git-guide/cn/stepup/stepup7_6.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.