What is Reverse Merge ( Revert Merge ) in SVN, a simple explanation and the step by step processes from start to finish

混江龙づ霸主 提交于 2019-11-28 09:43:40

From Tortoise User Guide:

If you want to merge changes back out of your working copy, to revert a change which has already been committed, select the revisions to revert and make sure the Reverse merge box is checked.

From my point of view a reverse merge is a "normal" commit which represents an "anti"-commit to one or more former commits. The former commit will still exist, but the changes become reverted through new "anti"-commit.

Short answer

A reverse merge is formally the same as a merge, but, of course, in reverse order. Changes from reversely-merged revisions become undone in your working copy.

Example

For example, if you want to go back from HEAD to rev. 123, you would reverse-merge like this, assuming your working copy is in HEAD state:

svn merge -r HEAD:123

This will set your working copy in the state of revision 123, but it will formally be based on HEAD. Your working copy state is then the same as if you had manually edited your files back to revision 123. Nothing will have changed in the repository as of yet.

Note that this is not the same as updating to revision 123. If you had done that, although your working copy files would have the same content in both cases, your working copy state would be different: SVN would know that your working copy was based on revision 123 instead of HEAD. If you then tried to commit the changes, it would tell you that you should update to HEAD first, which would undo the update to revision 123, assuming that you have not changed anything in the meantime.

Back to our original scenario. If you are satisfied with the reverse merge, then you can check it in to the repository:

svn commit -m "We undid all changes since r123."

Or, if you feel you have made a mistake, you can revert the reverse merge, which is something completely different, as it only sets your working copy back to the repository state is is based on (in our case, HEAD):

svn revert --recursive .

But be careful with that one, it irreversibly reverts your reverse merge :-). The dot refers to the current directory, and must be specified explicitly (as is not the case with most other SVN commands) as a safety measure to avoid accidentally reverting anything.

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