4

I migrated my repository from SVN to git. I used THIS site. Now I have a bug in revision X. How do I checkout from my git repository, knowing only the revision number from my old SVN repo?

Thank you for your Help.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Iron
  • 477
  • 4
  • 19

1 Answers1

8

You can find the git commit that corresponds to the Subversion revision with the git svn find-rev subcommand. For example, if you're looking for the commit that corresponds to Subversion revision 3431 you can do:

$ git svn find-rev r3431
42ed8bcf690fd0c655c5cee91b09258318fc56e8

Then, to checkout that revision, just use the object name from the first line, e.g. if it's:

commit 42ed8bcf690fd0c655c5cee91b09258318fc56e8
Author: torstenrohlfing <torstenrohlfing@42a5c34f-2066-0410-bec5-ba365beb4995>
Date:   Fri Sep 9 17:11:38 2011 +0000

    FIX: do not update time stamps on pre-existing files that did not get updated.


    git-svn-id: https://www.nitrc.org/svn/cmtk/trunk@3431 42a5c34f-2066-0410-bec5-ba365beb4995

You can do:

git checkout 42ed8bcf69

... to try that revision. (Note that this will detach HEAD, so if you don't know what that means, it would be worth searching for "detached HEAD" first :))

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • 1
    Hi, that does not work. I don't have this trunk-id in my commit log. – Iron Oct 10 '11 at 07:34
  • Do you have multiple git branches? Have you run `git svn rebase` recently? Can you find the most recent commit on your branch that has a `git-svn-id` line in the log at all? (e.g. with `git log --grep=git-svn-id`) – Mark Longair Oct 10 '11 at 08:06
  • git svn rebase: there is no upstream svn information in my working tree history. So didn't it fetch the whole repos? – Iron Oct 10 '11 at 10:26
  • Great, I'm glad to hear you got that sorted out :) – Mark Longair Oct 10 '11 at 11:34
  • 1
    A oneliner for this can be: `git svn fetch && git checkout $(git svn find-rev r3431)`. Note that this revision needs to exist. – Luís Bianchin Mar 07 '16 at 14:18