Skip to content

Instantly share code, notes, and snippets.

@rhowardiv
Created April 18, 2011 21:38
Show Gist options
  • Save rhowardiv/926247 to your computer and use it in GitHub Desktop.
Save rhowardiv/926247 to your computer and use it in GitHub Desktop.
Rebasing in SVN
# First look what happens with a simple but naive approach.
# I'll try recreating the branch in-place and merging in changes from the old version.
# Should be easy, right? svn never forgets, right? ...
cd ~/mybranch
SVH=/repo/root
# (for this approach we need the rev #'s for the start and end of the branch)
START_REV=$(svn log --stop-on-copy | grep '^r[0-9]' | tail -n 1 | sed s/^r// | awk '{print $1}')
END_REV=$(svn log --stop-on-copy | grep '^r[0-9]' | head -n+1 | sed s/^r// | awk '{print $1}')
svn delete $SVH/mybranch
svn copy $SVH/trunk $SVH/mybranch
svn up
# okay, now try the merge
svn merge -r$START_REV:$END_REV $SVH/mybranch
# whup, what just happened?
# The merge command follows the history of the source URL down through the _latest_ copy.
# So it's looking at trunk for the revision range we gave it, not our "old" branch.
# AN APPROACH THAT WORKS
# We just need to avoid trying to do the whole thing in-place.
# Move the old branch out of the way first:
svn mv $SVH/mybranch $SVH/mybranch-old
svn copy $SVH/trunk $SVH/mybranch
svn up
# Now the rebase merge works great. Also we don't need to remember the rev #'s.
svn merge $SVH/mybranch-old
svn commit
# Clean up the old branch
svn delete $SVH/mybranch-old
# And the log with mergeinfo is good
svn log -vg --stop-on-copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment