将分支合并回主干时如何避免 SVN 冲突
几周前,我开始对 SVN 存储库的主干进行更改,我认为这将是相当小的更改。
经过几个小时的工作,意识到更改的影响比我想象的更大,我认为立即将更改检查到主干中风险太大,所以我创建了一个分支,如下所示:
svn copy . https://my_svn_server/svn/blah/branches/my-branch
...然后做了一个svn 切换并愉快地继续在该分支工作。 到目前为止,一切都很好,直到我对所有更改感到满意并希望再次将它们合并回主干中。 因此,我将所有更改签入 my-branch,然后仔细按照所示的过程 这里 ...这就是我遇到麻烦的地方。 因为我从本地(客户端)存储库创建了 my-branch,该存储库中已经有大量(未签入)未完成的更改,所以合并不包括与这些更改相对应的差异,因此有合并中存在很多很多冲突,我必须手动解决——这是我不想做的事情,因为如果我搞砸了,它就会给错误留下空间。
我尝试通过减少合并期间指定的修订号来包含丢失的差异,例如通过执行 a
svn merge -r2818:2932 https://my_svn_server/svn/blah/branches/my-branch
而不是预期的
svn merge -r2819:2932 https://my_svn_server/svn/blah/branches/my-branch
...但这不起作用,因为我的分支在修订版 2818 中不存在,所以我只是得到一个错误:
svn: Unable to find repository location for 'https://my_svn_server/svn/blah/branches/my-branch' in revision 2818
所以这就是事情的现状。 这次我可以手动整理混乱,但我很好奇是否有办法处理这个问题,以便下次事情会变得更好。
我能想到的一种方法是创建 my-branch ,不是通过复制本地(客户端)存储库,而是通过制作 SVN trunk HEAD 的副本,然后将 my-branch 检出到单独的目录中,然后手动将本地(未签入)更改从 trunk 目录复制到 my-branch 目录,然后直接恢复本地 trunk...但这非常繁琐且容易出错。
当然有一种更好、更自动的方法来创建包含本地(未签入)更改的分支,然后将其合并回主干吗?
A few weeks ago I started making a change in my SVN repository's trunk that I thought was going to be fairly minor.
After a few hours of work, realizing that the change had bigger implications than I thought, I decided it was too risky to check my changes into the trunk right away, so I made a branch, like this:
svn copy . https://my_svn_server/svn/blah/branches/my-branch
... and then did a svn switch and happily continued working in that branch. So far, so good, until I get to the point where I'm happy with all the changes and want to merge them back into the trunk again. So I check in all the changes into my-branch, and then carefully follow the procedure shown here ... and here is where I ran into trouble. Because I created my-branch from the local (client-side) repository that already had a large number of (not-checked-in) changes outstanding in it, the merge doesn't include the diffs corresponding to those changes, and thus there are lots and lots of conflicts in the merge that I have to resolve by hand -- something I don't want to do since it leaves room for bugs to creep in if I mess it up.
I tried including the missing diffs by decrementing the revision number I specify during the merge, e.g. by doing a
svn merge -r2818:2932 https://my_svn_server/svn/blah/branches/my-branch
instead of the expected
svn merge -r2819:2932 https://my_svn_server/svn/blah/branches/my-branch
...but that didn't work, because my-branch didn't exist at revision 2818, and so I just get an error:
svn: Unable to find repository location for 'https://my_svn_server/svn/blah/branches/my-branch' in revision 2818
So that's about where things stand. I can manually sort out the mess this time, but I'm curious if there is a way to handle this so that things go better for me next time.
One way I can think of would be to create my-branch not by copying the local (client-side) respository but rather by making a copy of the SVN trunk HEAD, and then checking out my-branch into a separate directory, and then manually copying my local (not-checked-in) changes from the trunk directory to the my-branch directory, and then reverting the local trunk directly... but that's pretty tedious and error-prone as well.
Surely there is a better, more automatic way to make a branch that contains local (not-checked-in) changes, and later merge it back into the trunk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我想我已经弄清楚如何干净地进行合并(有趣的是,撰写问题通常可以澄清问题,不是吗?)。 解决方案是进行两次合并,一次合并是为了说明主分支(原样)和 my-branch 开头之间的差异,然后第二次合并是为了说明 my-branch 中所做的后续更改:
Okay, I think I've figured how to do the merge cleanly (funny how composing a question often clarifies the problem, isn't it?). The solution is to do two merges, one to account for the diffs between the main branch (as it was) and the beginning of my-branch, and then the second merge to account for the subsequent changes made in my-branch:
你的最后一个建议已经差不多了。 当你想要分支时,复制主干HEAD。 然后在您的工作副本中,
这会将您切换到分支,同时保留所有本地修改。 然后,您可以随时将更改提交到分支。
Your last suggestion is almost there. When you want to branch, copy the trunk HEAD. Then in your working copy,
This will switch you to the branch, while keeping all your local modifications. You can then commit your changes to the branch whenever you want to.