OK, I was struggling with this for a while, but found a work-around. You will lose history of the files prior to the current git repo revision, but history will be kept intact, and you don't have to --ignore-paths
. If rewriting history is an option, you should follow Ben Jackson's git svn reset
answer.
Let's say you are on r123, and don't have access to the folder scripts/
, which was created in r100. Somewhere down the line, you are granted access. This doesn't actually generate a revision, and is acceptable in SVN, but in git this effectively rewrites history. The git-svn repo continues being updated normally until something in scripts/
is modified (lets call it r126). Now git svn fetch
fails because it doesn't know what to do -- it has a diff for a file that doesn't exist!
The way I fixed it was the following:
# Clone the directory that is missing one revision before it is next changed
$ svn co -r 125 https://your-server/svn/bla/scripts
# copy the contents and (-p)reserve their attributes
$ cp -pr scripts/* ~/your-git-svn-mirror-on-r125ish/scripts
# Get the git-svn-id of the the most recent commit
$ cd ~/your-git-svn-mirror-on-r125ish
$ git log -1 | grep git-svn-id
git-svn-id: https://your-server/svn/bla/trunk@125 7b6d...daf
That git-svn-id
is the crux of the issue. It tells git-svn which commit maps to each revision. We're going to trick it into thinking our manual commit is actually an SVN commit.
# Add the missing new directory
$ git add scripts/
# An editor will open up, type a message warning this commit isn't a real svn revision
# The last line of your message should be the 'git-svn-id' from earlier.
$ git commit
<your message of warning>
git-svn-id: https://your-server/svn/bla/trunk@125 7b6d...daf
Now, there should be another commit that restores the files one commit before they are updated. Finally, we need to make git-svn rebuild the history, and take note of our new tricksy commit
# Backup the svn state in case something goes wrong
$ mv .git/svn .git/svn-BACKUP
# Cross your fingers, and fetch the changes from svn
# If your repo is large, it may take a long time to rebuild the mappings
$ git svn fetch
If all goes according to plan, you should have a repo with the new files, without rewriting history. You can git svn rebase
and git push
safely.
It may not be the most eloquent, but works as of git version 2.17.1
.