git rebase -i

來源:互聯網
上載者:User

標籤:

使用rebase -i會在終端出現一個互動頁面. 在這個互動頁面中我們可以對要rebase的commit做一定的修改. 

 

用法
git rebase -i <master>

把當前的分支的commit放在<base>後面, -i會開啟一個編輯器, 在這你可以為每一個commit輸入一個命令, 這個命令決定了如何把單個的commit傳輸到new base. 還可以改變commit列表的順序.

討論

大多數開發人員喜歡在merge一個分支到master的時候使用rebase -i打磨我們這個feature分支. 他給了我們機會合并一些commit, 刪除一些commit, 對commit進行排序.

 

例子
# Start a new featuregit checkout -b new-feature master# Edit filesgit commit -a -m "Start developing a feature"# Edit more filesgit commit -a -m "Fix something from the previous commit"# Add a commit directly to mastergit checkout master# Edit filesgit commit -a -m "Fix security hole"# Begin an interactive rebasing sessiongit checkout new-featuregit rebase -i master

最後的命令會開啟一個編輯器, 其中有兩行命令.

pick 32618c4 Start developing a featurepick 62eed47 Fix something from the previous commit

在這你可以修改pick命令. 在這個例子中, 我們使用squash合并這兩個commit:

pick 32618c4 Start developing a featuresquash 62eed47 Fix something from the previous commit

儲存關閉編輯器後rebase開始. 這是會開啟一個新的編輯器讓我們填寫commit描述.整個過程可視化如下:

注意了squash commit有一個新的ID號, 這表明他是一個全新的commit.

 

最後使用fase -forward merge整合feature分支:

git checkout mastergit merge new-feature

  

git rebase -i

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.