簡體   English   中英

如何在git日志歷史記錄中合並不同的提交

[英]how to merge different commit in git log history

假設我們提交了1-> 2-> 3-> 4-> 5,我認為歷史記錄可能太長了,我希望日志將1、2和3合並為一個,例如1'-> 2-> 3-> 4-> 5如何執行此操作,應該使用rebase嗎? 重新設置基准后,似乎無法推送到遠程回購。 提前致謝。

首先進入交互式變基模式

git rebase -i HEAD~5

(用要壓縮的提交數替換5)

然后按照git book Squashing commmits -part中的說明進行操作。

從git書中:

也可以進行一系列提交,然后使用交互式重新調整基准工具將其壓縮為單個提交。 該腳本在變基消息中添加了有用的說明:

 # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. # 

如果您指定“ squash”而不是“ pick”或“ edit”,則Git會同時應用此更改和更改,然后將提交消息合並在一起。 因此,如果要從這三個提交中進行單個提交,則使腳本看起來像這樣:

 pick f7f3f6d changed my name a bit squash 310154e updated README formatting and added blame squash a5f4a0d added cat-file 

保存並退出編輯器時,Git將應用所有三個更改,然后將您放回編輯器以合並三個提交消息:

 # This is a combination of 3 commits. # The first commit's message is: changed my name a bit # This is the 2nd commit message: updated README formatting and added blame # This is the 3rd commit message: added cat-file 

保存該內容時,您將擁有一個提交,該提交將介紹所有前三個提交的更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM