簡體   English   中英

線性化git歷史記錄,保留所有提交

[英]Linearize git history, preserving all commits

我想采用包含帶有合並提交的分支的git歷史記錄,並將其轉換為單個線性歷史記錄, 而無需將所有提交從分支壓縮到單個提交中。

也就是說,從以下開始:

* d667df5 (HEAD -> master) Modify merged file
*   233e181 Merge branch 'featurebranch'
|\
| * bca198d (featurebranch) Modify the second file
| * fdc4e08 Add a different file
* | 5e0c25f Modify file yet again
* | 2426135 Modify file again
* | eb56b32 Modify file
|/
* c94a83e Add a file
* bfbfaaa Initial commit

...我想要一行如下:

* d667df5 (HEAD -> master) Modify merged file
* bca198d Modify the second file
* fdc4e08 Add a different file
* 5e0c25f Modify file yet again
* 2426135 Modify file again
* eb56b32 Modify file
* c94a83e Add a file
* bfbfaaa Initial commit

我想要這個的原因是因為我在另一個開發人員的功能分支中工作。 在拉動我的更改時,他反復使用git pull (即創建合並提交)而不是重新設置。 我希望此功能分支的歷史記錄在將其合並到master之前是線性的。

注意我知道提交ID可能會在結果中有所不同。 我也知道重寫歷史的所有常見后果。

更新:不是這個問題的重復,因為我想保留分支中的單個提交而不是將它們壓縮成一個。

我想你想做一個改變。 確保工作目錄沒有任何變化。 我喜歡做的全球性想法是在一個新的分支上重新組織歷史,然后使這個分支成為主分支。

git checkout -b workingBranch featurebranch // create a new branch and checkout to featurebranch
git rebase 5e0c25f // This create your linear history, instead of merge. You may have to resolve commit for each commits of featurebranch
git checkout master
git reset --hard workingBranch // You will lose the commit d667df5 (HEAD -> master) Modify merged file. If it is not wanted, cherry-pick or rebase again
git branch -D workingBranch

我希望它有所幫助。

暫無
暫無

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

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