3 回答

TA貢獻1810條經驗 獲得超5個贊
您要執行的操作在git中稱為“壓縮”。執行此操作時有很多選擇(太多嗎?),但是如果您只想將所有未按下的提交合并到一個提交中,請執行以下操作:
git rebase -i origin/master
這將打開一個文本編輯器(-i用于“交互式”),其文件如下所示:
pick 16b5fcc Code in, tests not passing
pick c964dea Getting closer
pick 06cf8ee Something changed
pick 396b4a3 Tests pass
pick 9be7fdb Better comments
pick 7dba9cb All done
將第一個更改pick為squash(或s),第一個除外:
pick 16b5fcc Code in, tests not passing
squash c964dea Getting closer
squash 06cf8ee Something changed
squash 396b4a3 Tests pass
squash 9be7fdb Better comments
squash 7dba9cb All done
保存文件并退出編輯器。然后將打開另一個文本編輯器,使您可以將所有提交中的提交消息合并為一條大提交消息。
瞧!谷歌搜索“ git squashing”將為您提供所有其他可用選項的解釋。

TA貢獻1865條經驗 獲得超7個贊
如果提交次數很多,而您只想壓榨最近的X次提交,請找到要開始壓榨的提交的提交ID,然后執行
git rebase -i <that_commit_id>
然后按照leopd的答案所述進行操作,將除第一個之外的所有picks 更改為squashes。
范例:
871adf OK, feature Z is fully implemented --- newer commit --┐
0c3317 Whoops, not yet... |
87871a I'm ready! |
643d0e Code cleanup |-- Join these into one
afb581 Fix this and that |
4e9baa Cool implementation |
d94e78 Prepare the workbench for feature Z -------------------┘
6394dc Feature Y --- older commit
您可以執行以下操作(寫入提交次數):
git rebase --interactive HEAD~[7]
或者這(寫最后的哈希提交你不希望壁球):
git rebase --interactive 6394dc
- 3 回答
- 0 關注
- 699 瀏覽
添加回答
舉報