繁体   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