81

I'm using Subversion 1.4.6, and I cannot upgrade to version 1.5 right now.

The situation:

  1. The trunk has a lot of structural changes (i.e. moving files around, mostly).

  2. I have a branch that was recently merged from the trunk, but before the major changes.

What is the best way to merge the trunk to the branch?

What I had in mind:

  1. First carefully merge the branch to the trunk, by merging only the modified files in the branch to the trunk.

  2. Copy the trunk to the branch. What is the best way to do this without losing the branch history? Should I deprecate the branch and create a new one?


Okay, it looks like I didn't given SVN enough credit. It's smart enough after all. I was just put off by the output of "D" and "A", but in the background it did a move.

1
  • 4
    The question and the answers are relevant to very old SVN client and server versions and is not relevant to SVN 1.5+ and especially SVN 1.8+
    – bahrep
    Apr 13, 2017 at 6:46

4 Answers 4

89

Is there something that prevents you from merging all revisions on trunk since the last merge?

svn merge -rLastRevisionMergedFromTrunkToBranch:HEAD url/of/trunk path/to/branch/wc

should work just fine. At least if you want to merge all changes on trunk to your branch.

6
  • 3
    When I dried-run it, there where a lot of "D" and "A" for many files, since the files where moved in the trunk. My question is if SVN remembers the files' histories in this case.
    – Gilad Naor
    Dec 30, 2008 at 7:27
  • Did you use svn rename when moving files in the trunk? If you did, the history should remain. I think you should try this on a small scale - create a new repository, a trunk with a single file, a branch with a change, do an svn rename on the trunk and check whether history exists.
    – Yuval F
    Dec 30, 2008 at 7:42
  • 1
    How can I know which was the last revision merged from trunk to branch? Oct 13, 2009 at 17:46
  • 1
    in newer versions of svn it is a stored as a file property (somewhere?, perhaps the root directory). Older version do not store this info, you have to manually search for it. i.e. search the log for the commit of the last merge. (This is a major inconvenvience. Git, Mercurial, Bazaar do not have these limitations) Jul 14, 2010 at 7:50
  • 2
    A good guide available here: stereointeractive.com/blog/2009/02/17/… Mar 13, 2012 at 7:50
18

Last revision merged from trunk to branch can be found by running this command inside the working copy directory:

svn log -v --stop-on-copy
2
  • 4
    That just stops the log when the branch was created; it doesn't show any merges that happened after that point.
    – moswald
    Feb 10, 2010 at 20:45
  • 2
    Because, with that little caveat from @moswald, this can be quite useful to know. I don't see the problem. I don't usually have long lived branches (at most one week), so I normally only pull from trunk right before reintegration.
    – Andrew
    Jan 17, 2013 at 6:58
14

It is “old-fashioned” way to specify ranges of revisions you wish to merge. With 1.5+ you can use:

svn merge HEAD url/of/trunk path/to/branch/wc

Alternatively in 1.6+ there is no need for "HEAD", so you can use:

svn merge url/of/trunk path/to/branch/wc
5
  • 4
    I'm using 1.6.11 and it's making me enter a range.
    – Brent212
    Dec 13, 2013 at 0:55
  • 19
    Do you have to even say so much? What is wrong with 'svn merge /url/of/trunk' while in the working copy? Aug 13, 2014 at 4:25
  • 1
    svn: E195002: Invalid merge source 'HEAD'; a working copy path can only be used with a repository revision (a number, a date, or head)
    – Solo
    Nov 10, 2017 at 9:34
  • 3
    @Solo HEAD indeed requires you to specify a revision number, but there is no longer any need to use HEAD. As GreenAsJade mentions, "svn merge /url/of/trunk path/to/branch/wc" worked for me.
    – Tim Smit
    Nov 29, 2017 at 8:40
  • 2
    Answer should be revised to remove "HEAD"
    – Jeff
    May 25, 2018 at 19:28
0

The command svn merge --help (svn cli version 1.14.1) has a section titled The 'Feature Branch' Merging Pattern, that describes what you are trying to do.

The help text recommends that you run the following command in the root of your clean working copy:

svn merge ^/trunk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.