如何使用 git rebase 清理复杂的历史记录
在我的笔记本电脑、工作场所和家里的台式机上与六个不同的分支和合并工作了几周后,我的历史变得有点复杂。例如,我只是做了一次 fetch,然后将 master 与 origin/master 合并。现在,当我执行 git show-branches 时,输出如下所示:
! [login] Changed domain name. ! [master] Merge remote branch 'origin/master' ! [migrate-1.9] Migrating to 1.9.1 on Heroku ! [rebase-master] Merge remote branch 'origin/master' ---- - - [master] Merge remote branch 'origin/master' + + [master^2] A bit of re-arranging and cleanup. - - [master^2^] Merge branch 'rpx-login' + + [master^2^^2] Commented out some debug logging. + + [master^2^^2^] Monkey-patched Rack::Request#ip + + [master^2^^2~2] dump each request to log ....
我想用 git rebase 来清理它。为此,我创建了一个新分支 rebase-master,并在这个分支上尝试了 git rebase
我以为我在某个地方看到了这个问题的解决方案,但现在找不到了。有谁知道该怎么做?或者,当我开始删除已经合并的不需要的分支时,这些复杂的引用名称会消失吗?
我是这个项目的唯一开发者,所以没有其他人会受到影响。
After working for several weeks with a half dozen different branches and merges, on both my laptop and work and my desktop at home, my history has gotten a bit convoluted. For example, I just did a fetch, then merged master with origin/master. Now, when I do git show-branches, the output looks like this:
! [login] Changed domain name. ! [master] Merge remote branch 'origin/master' ! [migrate-1.9] Migrating to 1.9.1 on Heroku ! [rebase-master] Merge remote branch 'origin/master' ---- - - [master] Merge remote branch 'origin/master' + + [master^2] A bit of re-arranging and cleanup. - - [master^2^] Merge branch 'rpx-login' + + [master^2^^2] Commented out some debug logging. + + [master^2^^2^] Monkey-patched Rack::Request#ip + + [master^2^^2~2] dump each request to log ....
I would like to clean this up with a git rebase. I created a new branch, rebase-master, for this purpose, and on this branch tried git rebase <common-ancestor>. However, I have to resolve many conflicts, and the end result on branch rebase-master no longer matches the corresponding version on master, which has already been tested and works!
I thought I saw a solution to this somewhere but can't find it anymore. Does anyone know how to do this? Or will these convoluted ref names go away when I start deleting un-needed branches that I have already merged with?
I am the sole developer on this project, so there is no one else who will be affected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于可以强制推送分支的存储库(将远程历史记录替换为通过变基在本地创建的新分支),正常过程是:
但同样,只有当您是唯一从存储库拉取的人时,这才有效,即使如此,您也必须将一些本地分支重新初始化为已重写的新远程跟踪分支。
在变基会话中,您可以修剪 Git 提交和压缩历史记录 ,以获得您需要的历史记录。
The normal process, for repos where you can force push a branch (replacing the remote history by a new one created locally by a rebase), is to do:
But again, that is only valid if you are the only one pulling from your repos, and even then you will have to reinitialize some of your local branches to the new remote tracking ones that have been rewritten.
From rebase session, you can trimming Git commits and squash history, in order to get the kind of history you need.
清理错综复杂的历史的最好方法是保持历史的线性。您可以通过避免快进以外的任何类型的合并来做到这一点。
工作流程是这样的。
当需要将分支集成到 master 时,不要合并它。相反,根据主分支重新设置此分支的基础。这将使树枝看起来不再像树枝,而只是在树顶上更多地生长。您可以在变基期间解决任何合并冲突。
现在,将分支合并到 master 中。这将是一次快进合并。
现在将工作推向上游。
The best way to clean up a convoluted history is to keep the history linear. You do that by avoiding any kind of merge other than fast-forward.
The work flow goes like this.
When it's time to integrate the branch into master, don't merge it. Instead, rebase this branch against the master. That will make the branch no longer look like a branch, but but simply more growth on the top of the tree. You resolve any merge conflicts during the rebase.
Now, merge the branch into master. This will be a fast-forward merge.
And now push the work upstream.