Use git-svn with multiple svn repos and branches - git-svn

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.

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. :-)

git svn clone without cloning tags

I would like to skip import of all tags. is this the correct syntax?
git svn clone "http://svn/svn/IT_Udvikling" git-DataLicense --revision 37000:HEAD --trunk="/FID/DataLicense/trunk" --branches="/FID/DataLicense/branches" --no-minimize-url --authors-file=../authors-transform.txt
I am trying to skip import of tags because the git svn clone process takes forever. it has been running for 3 days now.
The best way to speed up git-svn for a one-time migration is to not use git-svn at all. Skipping the tags will probably not save you much time, as there are almost no commits that are unique to the tags in a typical SVN repository, just one per tag usually. But yes, if you don't specify -t or --tags directly or indirectly (e. g. by using -s or --stdlayout, then no tags should be fetched. But as I said, it will not speed up the process much.
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 that might exist.
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 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. :-)

Working with GIt without branches

I am trying to work with GIT, without creating private branches.
What that means is I directly work on my cloned repository (master)
Now, Is that the right way to use GIT? I run into many issues related to updating my repository (GIT PULL / GIT FETCH). And most of the time, I am not able to use GIT Merge.
Is there a particular way in which i can use GIT MERGE, GIT PULL, and GIT FETCH. That will help me?
Looks like the best way to work with GIT is have branches.
Branch 1
GIT Commit
GIT PUSH
GIT MERGE master ( to fetch the newer changes)
Branch 2
GIT Commit
GIT PUSH
master
GIT Merge branch1
GIT Merge branch2
I dont think there any other way. Please correct me if i am wrong?
Jan Krueger's extended cheat sheet will help you cover the basics, and will expose you some common commands for using git.
IMO, git is a brilliant DVCS. If you have time; take a look at the structure of git and try to catch the ideas behind its design. For example this Tech Talk by Linus Torvalds.
Note: It looks like you are missing some core ideas behind using git, so please try to learn general approach of git before tackling with commands.
Note 2: As being a stalker, you seem to have general problems with git. So I repeat my advice once more. Learn basics, complete a tutorial, read/listen/watch a few useful source from notable people about git.
Also read about git stash. It saves your local uncommitted changes so you can pull cleanly. Then run git stash pop to replay those changes on top.

git svn as a crutch for svn merging woes

Consider an svn repository that has branches that are not necessarily located in the usual trunk/tags/branches layout. I want to persuade git-svn to take two of those branches on board, plus whatever else it needs, so that I can use git as a merge tool to avoid various levels of heck that have been plaguing us with svn merging. If the branches are all in one place, there's --branches, but is there a way if they are not?
Do your git svn init ROOT_URL, then go in and edit your .git/config to add additional fetchlines:
[svn-remote "svn"]
url = https://svn.mcs.anl.gov/repos/mpi
fetch = mpich2/trunk:refs/remotes/trunk
fetch = mpich2/branches/dev/threads:refs/remotes/threads
fetch = mpich2/branches/dev/knem:refs/remotes/knem
fetch = mpich2/branches/release/MPICH2_1_0_8:refs/remotes/mpich2-1.0.8
Then git fetch and you should get all of the branches explicitly listed in your config file.
Be aware, however, that you may not want to actually pursue merging externally via git-svn. Git won't maintain the svn:mergeinfo properties for you, which will make going back to a native SVN-based merge workflow nearly impossible. You might also confuse git-svn quite a bit by cherry-picking or merging code that has already been committed to the actual SVN repo, since it searches for git-svn-id: "breadcrumbs" in the commit messages in order to figure out which SVN path should be used for git svn dcommit. See the CAVEATS section of the git-svn man page for additional info about this.
FWIW, I've also posted about this in longer form on my own site.

git-svn branch - How to keep branch in sync with trunk?

There are plenty of questions about git-svn workflow, but I haven't been able to figure this one out:
This section of the svn book talks about a common practice with SVN: you make a branch, and you keep merging changes from the trunk as the trunk gets updated, so that the branch always includes the latest changes.
I did git svn branch to create a branch on svn and then set up a tracking branch to work on it. These questions cover the process pretty well.
Now suppose there were changes made to the trunk, which I now want to merge into the branch. What is my best option? Note that I need to keep git-svn happy, and not mess up the work of people using the branch with subversion, so just doing a rebase would probably not work.
This question seems to talk about a similar situation, although it's pretty old, and I'm not sure what the bottom line there was - it seems to suggest I should git checkout master and then git rebase mybranch, but that can't be right.
I suspect the the answer should be something that has the effect of svn merge, preferably with setting the mergeinfo property, but alas, there is no git svn merge...
I don't really understand how this simple question was left unanswered for more than a week, with only 13 views so far. I guess it was my fault, bad question writing.
Anyway, I figured it out myself. Short version: just use git merge instead of git rebase.
My confusion came from using git rebase when syncing a branch with the changes in master. When working on local branches, this usually works great, and keeps the history clean. However, you should not rebase commits that you have pushed to a public repository, and the subversion repository is (apparenly) public enough. git merge, on the other hand, works beautifully, and doesn't have any problem.
So, the long answer is: when you want to merge the latest changes in the trunk into the svn branch you're tracking, just do:
git merge master
# Handle conflicts, git add when you're done
git commit
git svn dcommit
This will keep your branch in sync with trunk, but will not set mergeinfo, so you probably should not mix svn merge with this kind of practice.