Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git svn clone: How to defer fetch of revision history

I often have the case that I want to work on a SVN repository right away. But an ordinary git svn clone [url] also clones the entire history. So I want to speed things up. The first part is to fetch only the last revision into your Git repository. I do it like so:

URL=http://google-web-toolkit.googlecode.com/svn/trunk/ REV=`svn info $URL |grep Revision: | awk '{print $2}'` PROJECT_FOLDER=google-web-toolkit-readonly  git svn clone -r$REV:HEAD $URL $PROJECT_FOLDER 

(more info in the StackOverflow article: "How to git-svn clone last n revisions from svn"

This way I'm up and running and can work immediately. But without local copy of the history.

The question is, how do I afterwards fetch history from the svn repository?

And preferably, can this be done in chunks of, say 1000 revisions (in reverse order). Any help here would be greatly appreciated :)

like image 686
Jesper Rønn-Jensen Avatar asked Oct 12 '09 12:10

Jesper Rønn-Jensen


People also ask

How do I clone a SVN repository?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...

What is git SVN fetch?

This retrieves all the changes from the SVN repository and applies them on top of your local commits in your current branch. You can also use git svn fetch to retrieve the changes from the SVN repository but without applying them to your local branch.

What does git svn clone do?

The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of your SVN repo, the command needs to be configured differently.


2 Answers

I found out how it can be done. The trick is not to use git svn clone. Instead, use git svn init and git svn fetch individually. Modified the example:

URL=http://google-web-toolkit.googlecode.com/svn/trunk/ REV=`svn info $URL |grep Revision: | awk '{print $2}'` PROJECT_FOLDER=google-web-toolkit-readonly  mkdir $PROJECT_FOLDER cd !$ #goes into dir named $PROJECT_FOLDER git svn init -s $URL #-s implies --stdlayout with /trunk /tags /branches git svn fetch -r $REV  # hack, hack, hack  # or update history (fetch 50 revisions back each loop for (( r=$REV; r>0; r-=50 ));  do    git svn fetch -r $r:HEAD done 
like image 124
Jesper Rønn-Jensen Avatar answered Sep 20 '22 13:09

Jesper Rønn-Jensen


None of the suggested answers will work. git svn fetch with a revision will only retrieve newer revisions than what is already cloned. You may be able to use git svn reset to go back to an older revision and retrieve from there, but you'll have to do some dirty work afterwards to 'graft' your newer revisions back onto the full tree (the SHA1 of an SVN revision in git depends on the entire parentage of the revision). If you're handy with the scalpels git offers you, go for it.

It's much easier to just avoid the issue.

  • Do an initial clone of the last few revisions, so you can get working immediately;
  • Start another clone of the full history into another directory/git repository;
  • Work in your partial history as much as you want;
  • When the full clone completes, use an approach like http://www.sanityinc.com/articles/relocating-git-svn-repositories/ to copy your work from the partial repository to the full one.

So, that's a partial answer - how can you afterwards fetch history? Fetch it into another repo and copy what you need over. Can it be done in chunks of 1000 in reverse order? With the scalpels, and a lot of patience, it could, but it's unlikely worth it. The full fetch running forward is going to outrun the overhead of all those first revisions grabbed by each block you git svn fetch, and the fixup will get tedious.

like image 20
Chris Nash Avatar answered Sep 21 '22 13:09

Chris Nash