纠正 Git 中旧的合并混乱
我们是使用 Git 的小公司,而且我们都是新手。在我们使用 Git 并开始尝试功能分支和发布分支的一两个月里,我们遇到了像这样由合并冲突等引起的意大利面条般的小事件
: sstatic.net/BdRga.png" alt="在此处输入图像描述">
黑线是我的开发分支。忽略红色那个。您将看到一个提交如何脱离该开发树然后又合并回来。是否可以通过压平树来清除一些旧蜘蛛网?我的头脑现在大约有 500 多个提交。
我读到可以通过变基而不是合并来避免这种情况。
尽管这是一件微不足道的事情,但如果可能的话,我想解决这个问题,无论是作为强迫症还是清晰度问题。
谢谢。
We're a small using Git and all us are new to it. In the month or two that we've used Git and began experimenting with feature branches and release branches, we've run into little spaghetti incidents like this one caused by merge conflicts, etc:
The black line is my development branch. Ignore the red one. You'll see how one single commit has broken away from that development tree and then merged back. Is it possible to clear out some of these old cobwebs by flattening the tree? My head is now about 500+ commits away from this.
I've read that this can be avoided by rebasing instead of merging.
Even though, it's a trivial thing, I'd like to fix this if possible both as a matter of a OCD and clarity.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实想在 master 分支上提交
A
后线性化历史记录,您始终可以这样做:但是,这意味着您正在重写
master
的历史记录分支,所以如果你(强制)推送这个新版本,你必须向团队中的每个人介绍如何获取新版本并重置他们的主分支以匹配重写的版本。否则,人们很可能会拉动,这会将重写的分支与现有的分支合并,从而破坏练习的目标。这些小分歧通常发生在有人在其 master 分支上创建提交,但服务器上的 master 同时已移动时 - 这意味着当他们再次拉取时,需要合并提交。您可以通过以下措施来避免这种情况:
git pull --rebase
branch..rebase
和< code>branch.autosetuprebase 配置选项,这样他们就不会忘记添加--rebase
但是,就我个人而言,我不介意在历史中看到这些合并 - 有了一个好的历史查看器,仍然很清楚什么是正在进行中。
If you really want to linearize the history after a commit
A
on the master branch, you could always do:However, this means that you're rewriting the history of your
master
branch, so if you do (force-) push this new version, you'll have to brief everyone in your team about how to fetch the new version and reset their master branches to match the rewritten version. Otherwise, people are likely to pull, which will merge the rewritten branch with their existing one, defeating the object of the exercise.These small divergences typically happen when someone creates a commit on their master branch, but master on the server has moved on in the mean time - this means that when they pull again, a merge commit is required. You can avoid this in the future either by measures like:
git pull --rebase
branch.<name>.rebase
andbranch.autosetuprebase
config options, so that they don't forget to add the--rebase
However, personally I don't mind seeing these merges in the history - with a good history viewer it's still very clear what's going on.