Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I git svn rebase to a certain svn revision? (Similar to svn up -r ...)

Tags:

rebase

git-svn

Short question: what is the git-svn equivalent of svn up -r r1130 to update only to a numbered commit (with the svn number)?

I am using git-svn so I can both use git and manage (many) local branches of my team's svn repository. I have a version of the software that I hack up to work with a particular hardware setup. Since I last worked with it, the svn repo has moved forward past a stable, good point for this work. I want to update the local branch to a numbered revision that represents the stable commit. I could do this in svn with svn up -r r1130, but I prefer git.

I keep forgetting how I have done this in the past and finding myself searching SO and the help pages trying to find the best way. Perhaps there is a differently worded Q&A that I'm missing?

It is easy enough to just check out the older revision on a clean tree, but when I am carrying commits on top of the tree, the "rewinding head to replay your work on top of it..." part that I usually love means that I will be going to a point in the tree before my changes were added!

For now, I am going to git svn rebase and then rebase interactively to back out the commits I don't want, but I am having trouble believing this is the best or even a good way of doing this.

like image 205
sage Avatar asked Apr 19 '12 01:04

sage


People also ask

What is the equivalent of SVN update in git?

Getting the latest changes from SVN The equivalent to git pull is the command git svn rebase . This retrieves all the changes from the SVN repository and applies them on top of your local commits in your current branch.

What does Git SVN rebase do?

Normally, the "git svn clone" and "git svn rebase" commands attempt to recreate empty directories that are in the Subversion repository. If this option is set to "false", then empty directories will only be created if the "git svn mkdirs" command is run explicitly. If unset, git svn assumes this option to be "true".

Can I use Git and SVN at the same time?

git works perfectly fine with a svn repository on the other side, why not benefit from that? Certainly possible, and a fair move towards your colleagues, not to push unfinished changes. however there is one huge danger hidden in there: you will tend to make very few commits to the companies repository.

How do I clone a SVN repository?

You can clone from a SVN repo using the git svn clone command. -s = If your SVN repo follows standard naming convention where main source is in “trunk”, branches are created in “branches”. Here we are telling git svn that trunk is the “trunk” directory, maintenance is the “branches” directory etc.


2 Answers

I prefer rebase because git-svn is going to have to rebase your changes anyway before a dcommit. Try this instead:

git checkout `git svn find-rev r1241`  # Go to the svn version of interest
git checkout -b master_r1241           # Create a new brach matching it
git checkout hwTesting                 # Merge previously created changes
git rebase master_r1241                # rebase on top of not quite up-to-date master branch

You could do this in one step also: (could always revert using reflog or rebase --abort if things go horribly wrong).

git checkout hwTesting                 # Checkout feature branch
git rebase `git svn find-rev r1241`    # rebase on top of not quite up-to-date master branch
like image 156
mk2337 Avatar answered Sep 24 '22 19:09

mk2337


There doesn't seem to be a way to do it in one step. You can, however, easily find the corresponding git commit id for a given svn revision number. Try this:

git svn find-rev rN

where N is the revision number you want. After that, use git checkout to checkout that specific point in the history.

like image 35
Peter Bratton Avatar answered Sep 24 '22 19:09

Peter Bratton