簡體   English   中英

在不進行所有提交的情況下重寫git repo歷史記錄

[英]Rewriting git repo history without going through all commits

我想在git存儲庫中折疊一些丑陋的合並,而不必重新建立此后發生的所有提交。 例如:

* sha0                       *
| ... ~50 commits            | ... ~50 commits
*                            *
* sha1             -->       * sha1
|\                           * sha2
* *                          *
* |\                         ...
|/  *
*   |
*  /
| /
|/
* sha2
*
...

這樣做的最佳方法是什么?

編輯:

在對其中一項答復提出建議后,我意識到我應該澄清一下:

  • 我想重寫sha1和sha2之間的歷史記錄
  • 我需要保留在sha0和sha1之間的提交

最終,您將不得不重新定級。 一種簡單的方法是在sha1處創建臨時分支,然后進行soft reset ,然后soft reset基准。

git checkout -b temp_branch sha1

git reset --soft sha2

git commit -m <message>

git checkout master

git rebase --onto temp_branch sha1

git branch -d temp_branch

暫無
暫無

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

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