How do I properly branch post-commit and revert the trunk in svn?

你。 提交于 2019-11-29 03:03:23

问题


I have some commits that I've decided, after the fact, are going to be more branch work then trunk work. How do I create the branch and revert the trunk while still ensuring merging isn't painful later?

Is it as simple as copying the current trunk to a branch and reverting the trunk? Or will this create headaches later?


回答1:


I think Philips method would be something like the following, assuming the last "good" revision was at 100 and you are now at 130, to create the new branch:

svn copy -r100 svn://repos/trunk svn://repos/branches/newbranch
svn merge -r 100:130 svn://repos/trunk svn://repos/branches/newbranch

Note the idea is to preserve the changes made in those revisions so you can apply them back to trunk.

To revert trunk:

svn merge -r130:100 .
svn ci -m 'reverting to r100 (undoing changes in r100-130)' . 

(It wouldn't matter which order you performed these in, so you could revert trunk before creating the branch.)

Then you could switch to the new branch you created in the repo:

svn switch svn://repos/branches/newbranch workdir



回答2:


To be honest, I copy my changes off, revert trunk, branch, then commit my changes to the branch. The main reason being ease of merge later (if you later merge from the trunk to the branch at branch point, the merge will contain a revert of your initial changes).

This may not be the "correct" way, as you can always skip revisions when merging, but it is normally much less of a headache for me later on. Disclaimer: I'm no svn guru, so it may be easier for me because I'm doing it wrong - but I do use svn quite a lot.




回答3:


There's nothing wrong with following Philip's method, other than it leaves some "cruft" in the revision history. If you wanted to removed them for tidiness sake, and the revisions are at HEAD you could remove them from the repository by following these instructions.

Update: Philip's method is better than the one suggested in the question for the reasons he stated. Mine and Philip's methods would be similar, except that insead of reverting the trunk I propose removing the revisions from the revision history. (as I said, this can only be done if all the revisions you want to remove are at the HEAD of the repository.)




回答4:


I don't have svn available right here but this is how I would try to do it :

Determine the point in history where you started committing bad stuff (say revision "100" while you are at "130")

svn copy trunk branch # create your branch while preserving history
svn copy trunk@100 trunk #replace current revision with revision 100  

This should bypass the bad history without adding a reverse merge (actually you are bypassing the history of the trunk between 100 and 130 but you kept a link to that history in the branch and accessing trunk while forcing the rev will still yield the correct history)

Then

svn switch branch workdir

this should work if you want to completely remove the changes from trunk. If there are small ones you want to keep you can cherry pick them again from branch to trunk (if you use svn 1.5 it will track merge points and avoid spurious conflicts)



来源:https://stackoverflow.com/questions/148902/how-do-i-properly-branch-post-commit-and-revert-the-trunk-in-svn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!