git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-svn merge helper

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
Sep 30, 2007, 11:05 UTC
Message-ID
<20070930110550.GA4557@atjola.homenet>
Hi,

I recently discovered git-svn and absolutey love it. One thing that I'm missing though, is an equivalent of "svn merge" for merging between svn remotes, to support the SVN way of using "squashed" merges, where you just note the merge meta-data in the commit message. "git merge" didn't work for me (and probably isn't expected to work) to merge between two svn branches, so I've resorted to cherry-picking the required commits one by one into a temporary branch and then squashing them together by doing a --squash merge with a second temporary branch (as in [1]).

Of course that becomes extremely annoying if there are like 200 commits to merge, so I came up with the following script to help me. It does just what I described above, but automated. Usage is like this:

git-svn-merge trunk 123 543

Which does the same as "svn merge -r123:543 trunk-url", except for being incremental (ie. no huge one-time patch, eventually causing a massive set of conflicts) and often faster.

In case of conflicts, it bails out and let's you fix them. Then you can just re-run it with the same parameters again, as it automatically determines where to start cherry-picking if you're currently on the merge branch.

It's neither complete nor nice to look at, but it more or less gets the job done, so I thought I'll just post it here, maybe someone picks it up and brings it into shape.

Thanks, Björn

[1] http://cheat.errtheblog.com/s/gitsvn/
#!/bin/sh
BRANCH=$(git branch | grep \* | cut -d ' ' -f2)

START=$(git svn find-rev r$2 $1) END=$(git svn find-rev r$3 $1)

if echo $BRANCH | grep -q svnmerge/
then
	START=$(git svn find-rev r$(git svn find-rev HEAD) $1)
else
	git checkout -b svnmerge/$BRANCH
fi
for HASH in $(git log --pretty=format:%H --reverse $START..$END)
do
	git cherry-pick $HASH || exit
done

git checkout $BRANCH git checkout -b svnmerge/$BRANCH-squashed git merge --squash svnmerge/$BRANCH git commit -m "Merged changes from revisions $2-$3 from $1 into $BRANCH."

Next: Benoit SIGOURE
Message 1 of 10 in “git-svn merge helper”
  1. Björn SteinbrinkSep 30, 2007
  2. Benoit SIGOURESep 30, 2007
  3. Björn SteinbrinkOct 1, 2007
  4. Benoit SIGOUREOct 1, 2007
  5. Björn SteinbrinkOct 2, 2007
  6. Steven WalterOct 2, 2007
  7. Björn SteinbrinkOct 2, 2007
  8. Steven WalterOct 3, 2007
  9. Björn SteinbrinkOct 3, 2007
  10. Andreas EricssonOct 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.