reconcile git svn after git filter-branch - git-svn

I am attempting to convert a SVN repository into git. The SVN repository is being actively used, while we work out the details of converting.
I followed all the guides and created an author mapping file and cloned the SVN repository.
> git svn clone https://host/svn/Project --trunk=trunk -A svn-author-map.txt
Concurrently with this switch to git, I would also like to atone for some of the sins of the SVN past (stored passwords, etc). However as soon as I alter any of the history with git filter-branch or BFG, I seem to break the ability to incorporate any updates from SVN.
> git svn fetch --fetch-all
fatal: Invalid revision range [sha from clone]..refs/remotes/trunk
Is there a way to refresh the git-svn ids to the post filter-branch ids? Or is there no going back after changing any history?

If you edit the history after conversion, then maintaining the link can become tricky.
I guess the best options are either do one-time conversion (make svn source read-only, fully switch to edited git repo), or just keep the history as is and change the leaked passwords instead.

Related

I'd like to move over a branch from an svn location and use it as the master in the github location

I'd like to move over a branch from an svn location and use it as the master in the github location. Can anyone tell how to do this?
You can follow this process by Tiago Rodrigues (trodrigues)
If you want to clone an svn repository with git-svn but don't want it to push all the existing branches, here's what you should do.
Clone with git-svn using the -T parameter to define your trunk path inside the svnrepo, at the same time instructing it to clone only the trunk:
git svn clone -T trunk http://example.com/PROJECT
If instead of cloning trunk you just want to clone a certain branch, do the same thing but change the path given to -T:
git svn clone -T branches/somefeature http://example.com/PROJECT
This way, git svn will think that branch is the trunk and generate the following config on your .git/config file:
[svn-remote "svn"]
url = https://example.com/
fetch = PROJECT/branches/somefeature:refs/remotes/trunk
If at any point after this you want to checkout additional branches, you first need to add it on your configuration file:
[svn-remote "svn"]
url = https://example.com/
fetch = PROJECT/branches/somefeature:refs/remotes/trunk
branches = PROJECT/branches/{anotherfeature}:refs/remotes/*
The branches config always needs a glob. In this case, we're just specifying just one branch but we could specify more, comma separating them, or all with a *.
After this, issue the following command:
git svn fetch
Sit back. It's gonna take a while, and on large repos it might even fail. Sometimes just hitting CTRL+C and starting over solves it. Some dark magic here.
After this, if you issue a git branch -r you can see your remote branch definitions:
git branch -r
anotherfeature
From there you can define a master branch, and push it to a GitHub repo:
git checkout -b master anotherfeature
git remote add origin https://github.com/user/arepo.git
git push -u origin master
If you insist on using git-svn, VonC already provided a good answer.
But for a one-time migration git-svn is not the right tool for conversions of repositories or parts of repositories. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should not use git-svn, but svn2git which is much more suited for this use-case.
There are plenty tools called svn2git, the probably best one is the KDE one from https://github.com/svn-all-fast-export/svn2git. I strongly recommend using that svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.
You will be easily able to configure svn2gits rule file to produce the result you want from your current SVN layout, including any complex histories like yours that might exist and including producing several Git repos out of one SVN repo or combining different SVN repos into one Git repo cleanly in one run if you like.
If you are not 100% about the history of your repository, svneverever from http://blog.hartwork.org/?p=763 is a great tool to investigate the history of an SVN repository when migrating it to Git.
Even though git-svn or the nirvdrum svn2git is easier to start with, here are some further reasons why using the KDE svn2git instead of git-svn is superior, besides its flexibility:
the history is rebuilt much better and cleaner by svn2git (if the correct one is used), this is especially the case for more complex histories with branches and merges and so on
the tags are real tags and not branches in Git
with git-svn the tags contain an extra empty commit which also makes them not part of the branches, so a normal fetch will not get them until you give --tags to the command as by default only tags pointing to fetched branches are fetched also. With the proper svn2git tags are where they belong
if you changed layout in SVN you can easily configure this with svn2git, with git-svn you will loose history eventually
with svn2git you can also split one SVN repository into multiple Git repositories easily
or combine multiple SVN repositories in the same SVN root into one Git repository easily
the conversion is a gazillion times faster with the correct svn2git than with git-svn
You see, there are many reasons why git-svn is worse and the KDE svn2git is superior. :-)

Use git-svn with multiple svn repos and branches

I have a svn branch that I had been working on and decided to start using git-svn to work locally. Now I have two problems. I want to move my work into another svn repository (on the same host) but I'd first like to merge the latest work from trunk. How would I do this with git-svn? Also, how would I continue my work in a separate svn-repo while continually merging work from the original repo? Also, I don't want to checkout the entire history from the original trunk because the project is rather huge. I am new to git and to git-svn, though I've taken a crash course in git branching and I feel confident enough to use advanced commands like rebase and cherry-pick. I mainly need to know how to apply these concepts thru git-svn. Do the svn repos get setup as a git remote somehow? Are there good resources on the net explaining how it works? Any guidance is much appreciated.
Create your Git repo with git svn init -s <url>.
git config --edit, add several svn-remotes for each of your Subversion repos. Later you'll use the -R option to all git-svn commands to select which svn-remote to use.
Tweak svn-remote branch mappings as needed. Keep in mind that the default refs/remotes/* namespace specifies remote branches — not Git remotes. (You'll have just a single git remote named . which I don't recommend pushing/pulling to/from).
You can easily design your remote branches namespace to keep branches from different Subversion repos separated (e.g. refs/remotes/repoA/*, /refs/remotes/repoB/* etc).
git svn fetch. This has options to scan history only partially, e.g. starting from a specific revision. Please read the manpage on instructions how to do this.
You can also ignore specific paths and/or branches here.
Work with Git as usual, trying to keep your commits as linear as possible. Rebase often. Merge commits are fine (git-svn will even set svn:mergeinfo property), but holy cow be careful (and read the manpage for caveats). Understand that Git commits with git-svn-id tags are immutable, and push -f won't save you. For example, it's forbidden to amend or rebase already dcommit'ed changes.
Are there good resources on the net explaining how it works?
By far the best resource is the manpage. The next after it is git-svn source.

How do I change ignore-paths on an existing git-svn repo?

I have an already existing git-svn repo with an ignore paths in my .config file that looks like this:
ignore-paths = ^(?!(Path1/Proj1|Path1/Proj2|Path2/Proj3))
This works well.
Someone added a new project in svn that I now need in my git repo.
If I change ignore-paths to what's below and issue a fetch or a rebase, I never see Path2/Proj4
ignore-paths = ^(?!(Path1/Proj1|Path1/Proj2|Path2/Proj3|Path2/Proj4))
In the past, I've always given up and blasted away my git repo and recreated it. Is there a better way?
After editing the ignore-paths you need to
git svn reset -r <n> -p # where <n> is the SVN revision where the new path was added.
git svn fetch
git rebase # or reset
Reference git-svn(1):
reset
Undoes the effects of fetch back to the specified revision.
This allows you to re-fetch an SVN revision. Normally the
contents of an SVN revision should never change and reset
should not be necessary. However, if SVN permissions change,
or if you alter your --ignore-paths option, a fetch may fail
with "not found in commit" (file not previously visible) or
"checksum mismatch" (missed a modification). If the problem
file cannot be ignored forever (with --ignore-paths) the only
way to repair the repo is to use reset.
Only the rev_map and refs/remotes/git-svn are changed (see
$GIT_DIR/svn/*\*/.rev_map.* in the FILES section below for details).
Follow reset with a fetch and then git reset or git rebase to
move local branches onto the new tree.

Commit git-svn changes to SVN repo

we have a central SVN repo in our company. I use git-svn on my laptop to be able to use a repo, when I'm not connected to the company network.
Now I was 3 weeks on a business trip and committed a lot to my local Git repo. There were also many commits to the SVN repo.
When I try "SVN Rebase" I have to edit conflicts in each of my Git changesets. What I would like to do is just to commit all of my local changes at once and then edit conflicts only once.
I'm fairly new to Git, so I don't know how this is done properly and if this is the best way.
I use TortoiseGit on Windows, so up to now I didn't really care about the command line.
Thanks for your help.
Once you go through conflict resolution in git-svn rebase once you are in a new tree with new commits that include your resolutions. A future git-svn rebase will not encounter the same problems (unlike repeated merges, which is where rerere comes in handy).
If by "commit all my local changes at once" you mean you want to fold all of your commits into a single commit in git (and later SVN) then you can use git rebase -i to "squash" all of your commits into a single commit. You should not include any revisions that have already been sent to SVN with dcommit in that rebase -i because you are rewriting history. You will still have to resolve conflicts when you git-svn rebase just like you would if you were using only SVN and did svn update.

How to recover from an unwanted rename using git-svn: "Transaction is out of date"

I'm using git-svn. I've moved file 'A' to 'B' and I'm up to date with the svn HEAD (using git svn rebase). I can commit all other changes without problems. Now I've decided that I want to move 'B' back to 'A' and commit that change.
When I do the move and commit to my local master it works fine, but I get the following when doing a git svn dcommit:
Transaction is out of date: Out of date: 'A' in transaction '3652-1' at /opt/local/libexec/git-core/git-svn line 570
So I tried to copy and delete in a separate commit which resulted in:
Item already exists in filesystem: File already exists: filesystem '/usr/svn/db', transaction '3652-1', path 'A' at /opt/local/libexec/git-core/git-svn line 4735
I've recovered from this situation with plain svn by using the workarounds like the one described in the documentation, but I don't know how to recover with git-svn. What is going on and how do I fix it?
Removing .git/svn did not work for me. Instead, here's how I resolved:
Deleted the offending directories from the repository (But I'm not sure that this is necessary. In hindsight I think I could have skipped this step)
git svn rebase
During the rebase, there were some conflicts. For each conflict, I resolved the conflicts in text editor, then used git add <file-in-conflict> and then git rebase --continue
After rebase completed successfully, git svn dcommit ran successfully!
I can't claim to understand what's really going on under the hood in git-svn in this case (although the underlying SVN issue makes perfect sense). My usual strategy when git-svn gets confused somehow is to blow away the .git/svn metadata directory (as in this post). This almost always saves me from odd synchronization issues between the git and SVN repositories.
It happened with me when I interrupted the dcommit process.
Follow these steps to recover from error:
git svn rebase
You will get conflicts in files. Resolve the conflicts & then git add filename (in which conflict occurred) for each file.
Now do git svn dcommit. It will be pushed to remote successfully.