线性化git历史记录,保留所有提交 [英] Linearize git history, preserving all commits

查看:158
本文介绍了线性化git历史记录,保留所有提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取一个包含合并合并分支的git历史记录,并将其变成单个线性历史记录,将分支中的所有提交压缩为单个提交.

I would like to take a git history that contains branches with merge commits, and turn it into a single linear history without squashing all the commits from the branch into a single commit.

也就是说,从以下内容开始:

That is, starting from the following:

* 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

...我想一行如下:

... I would like a single line as follows:

* 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(即创建合并提交)而不是重新设置基础.在合并到母版之前,我希望此功能分支的历史是线性的.

The reason I want this is because I am working in a feature branch with another developer. When pulling my changes he has repeatedly used git pull (i.e. creating merge commits) rather than rebasing. I want the history of this feature branch to be linear before merging it into master.

NB我知道提交ID的结果可能会有所不同.我也知道重写历史记录的所有常见后果.

NB I am aware the commit IDs will likely be different in the result. I am also aware of all the usual consequences of rewriting history.

更新:此问题不是重复的,因为我想保留个人在分支中提交而不是将其压缩为一个.

Update: Not a duplicate of this question since I want to preserve the individual commits in the branch rather than squash them into one.

推荐答案

我想您想进行基础调整.确保工作目录中没有任何更改.我想做的全球构想是在新的分支机构工作以重组历史记录,然后将该分支机构变为主要分支机构.

I guess you want to make a rebase. Be sure to not have any changes in working dir. The global idea I like to do is to work on a new branch to reorganize the history, then make this branch the master one.

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

希望对您有帮助.

这篇关于线性化git历史记录,保留所有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆