OMFG, do I really have to get back to SVN??? Part 1
well, I'm not gonna do a Git vs SVN battle here, there are thousands of sites that say Git is better, easier, faster, so I don't need to repeat that, my point here is:
I have to use SVN after having using Git for several months and I don't want to get back to the SVN approach. what can I do?
well, Git has a beautiful SVN wrapper, here is how to use it:
Init
$ git svn init -s https://svn_repository_url your_dir
Initialized empty Git repository in your_dir
$ cd your_dir
$ git svn fetch
r1 = 6bdec5c6d7f42f7af9a905ea84ea7db60a364b70 (trunk)
A README
r2 = 7219311784935beded8254aa19d3f2635af4ec7a (trunk)
M README
r3 = 58136685ff4688df3106e7b30205ec862677436c (trunk)
Found possible branch point: https://svn_repository_url/trunk => https://svn_repository_url/branches/my_new_branch, 6
Found branch parent: (my_new_branch) 58136685ff4688df3106e7b30205ec862677436c
Following parent with do_switch
Successfully followed parent
r4 = 1221404c1cce31b94851f32f5ab3497f74998f03 (my_new_branch)
Found possible branch point: https://svn_repository_url/trunk => https://svn_repository_url/branches/another_branch, 6
Found branch parent: (another_branch) 58136685ff4688df3106e7b30205ec862677436c
Following parent with do_switch
Successfully followed parent
r5 = 611a1b5394afa69c6b669f58c0fc38629c2b4da0 (another_branch)
the -s option means that this repository has a standard layout, which means that it has at least 3 folders:
trunk #the main development folder
branches #a container folder for branches
tags #a container folder for tags
Clone (init and fetch in one step)
$ git svn clone -s https://svn_repository_url
At this moment you have one local branch: master
and 3 remote branches: trunk (for git, now this is a branch, not a simple folder), my_new_branch and another_branch
the git master branch is tracking the svn trunk branch, but we don't have local branches tracking any of the other 2 branches yet.
To keep update your working copy just perform:
$ git svn rebase //svn update
In order to keep updated your working copy must be clean, so if you have some changes you won't be able to commit, in such case use:
$ git stash
Saved working directory and index state WIP on master: 214231d a commit message
HEAD is now at 214231d a commit message
$ git svn rebase //let's suppose that we got conflicts
M README
Auto-merging README
CONFLICT (content): Merge conflict in README
Failed to merge in the changes.
$ git mergetool //solve conflicts
$ git rebase --continue
Applying: a commit message
$ git stash pop //you will recover your changes, but let's suppose again that we got conflicts too
Auto-merging README
CONFLICT (content): Merge conflict in README
$ git mergetool //solve conflicts
$ git commit -m "your commit message" //always, after solving a conflict we have to commit
[master 11a2588] your commit message
1 files changed, 1 insertions(+), 1 deletions(-)
I have to say that this is one of the worst scenarios while updating from an svn server, don't be scared about conflicts it's not that hard to solve them.
here is another example but now without conflicts
$ git stash
Saved working directory and index state WIP on master: 6a4131d another message
HEAD is now at 6a4131d another message
$ git svn rebase
$ git stash pop
$ git commit -m "your commit message"
[master 12c2a88] your commit message
1 files changed, 1 insertions(+), 1 deletions(-)
now, finally, to commit changes to the svn server
$ git svn dcommit //svn commit
Committing to https://svn_repository_url ...
M README
Committed r6
M README
r6 = 418ad2c0003c0d642a60ce889fd8931d174009a8 (git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
trunk/README: locally modified
M README
Committed r7
M README
r7 = 731f821a38cc401737756470bed2a546e3e6554a (git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
ok, but, what did just happen?
1. I made 2 git commits (to the local git repository)
2. In this way each commit made with git was "transformed" into a svn one.
3. so, we went from revision 5 to revision 7
then, if other developers using SVN want your changes, they would do:
$ svn update U trunk/README Updated to revision 7.
ok, but, what about all the git sexiness to work with branches and tags?
we will see it in the next part of this post...see you.
February 7th, 2010 - 12:31
Thank you for your comment about the blogpost; I’m using a Wordpress theme called Lighword by Andrei Luca, by the way, so, thank Andrei for the look and feel of this blog. see you.
February 6th, 2010 - 19:52
Nice blogpost, amazing looking website, added it to my favs.
October 22nd, 2009 - 16:08
Hello from Russia!
Can I quote a post in your blog with the link to you?
October 22nd, 2009 - 16:20
of course you can quote the post whereever you want, Polprav, just could you let me know where you’ll quote my post? you don’t need to do so, but I’d like to know it, hehe, see you, man