Skip to content

Commit 0bec5db

Browse files
authored
Adapted to current git version
The on-disk image of a git repository has changed in recent versions of w.r.t to how svn-git stores remote branches and tags. As a consequence the bash commands told in this section of the book did not work anymore. My proposal solves this issue. I tested it today against 2.1.4, so I assume the change happened with v2.0 or v2.1 and should work with newer Git versions, too.
1 parent e95aba0 commit 0bec5db

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

book/09-git-and-other-scms/sections/import-svn.asc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This makes your `import` command look like this:
3737
[source,console]
3838
----
3939
$ git svn clone http://my-project.googlecode.com/svn/ \
40-
--authors-file=users.txt --no-metadata -s my_project
40+
--authors-file=users.txt --no-metadata --prefix "" -s my_project
4141
----
4242

4343
Now you should have a nicer Subversion import in your `my_project` directory.
@@ -76,18 +76,16 @@ To move the tags to be proper Git tags, run:
7676

7777
[source,console]
7878
----
79-
$ cp -Rf .git/refs/remotes/origin/tags/* .git/refs/tags/
80-
$ rm -Rf .git/refs/remotes/origin/tags
79+
$ for t in $(git for-each-ref --format='%(refname:short)' refs/remotes/tags); do git tag ${t/tags\//} $t && git branch -D -r $t; done
8180
----
8281

83-
This takes the references that were remote branches that started with `remotes/origin/tags/` and makes them real (lightweight) tags.
82+
This takes the references that were remote branches that started with `refs/remotes/tags/` and makes them real (lightweight) tags.
8483

8584
Next, move the rest of the references under `refs/remotes` to be local branches:
8685

8786
[source,console]
8887
----
89-
$ cp -Rf .git/refs/remotes/origin/* .git/refs/heads/
90-
$ rm -Rf .git/refs/remotes/origin
88+
$ for b in $(git for-each-ref --format='%(refname:short)' refs/remotes); do git branch $b refs/remotes/$b && git branch -D -r $b; done
9189
----
9290

9391
It may happen that you'll see some extra branches which are suffixed by `@xxx` (where xxx is a number), while in Subversion you only see one branch. This is actually a Subversion feature called "peg-revisions", which is something that Git simply has no syntactical counterpart for. Hence, `git svn` simply adds the svn version number to the branch name just in the same way as you would have written it in svn to address the peg-revision of that branch. If you do not care anymore about the peg-revisions, simply remove them using `git branch -d`.

0 commit comments

Comments
 (0)