Please provide tips for effectively using git with svn. What are your "best practices"?
The difference between Git and SVN version control systems is that Git is a distributed version control system, whereas SVN is a centralized version control system. Git uses multiple repositories including a centralized repository and server, as well as some local repositories.
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.
What is Git-SVN? The git-svn tool is an interface between a local Git repository and a remote SVN repository. Git-svn lets developers write code and create commits locally with Git, then push them up to a central SVN repository with svn commit-style behavior.
When you create the clone, use --prefix=svn/
. It creates nicer branch names.
Also, don't neglect the --trunk
, --tags
, and --branches
arguments when doing clone
or init
.
Fetching is one of the more time-consuming steps, so set up a cron job to do git svn fetch
in the background. This is safe because fetching doesn't affect any of your working branches.
( Background info on git svn fetch
: This command is executed first whenever you do git svn rebase
, so by doing this step ahead of time, your git svn rebase
call will usually be faster. The fetch
command downloads SVN commits and sticks them into special branches managed by git-svn. These branches are viewable by doing git branch -r
, and if you did the above step, they start with "svn/". )
Make sure you know how to use git reflog
. I've had a few occasions where git svn dcommit
died (usually because I tried to check in something huge) and my commit seemed to be lost. In every case, the commit was easily found in the reflog.
Here's some that I recently learned:
git svn rebase
before doing git svn dcommit
dcommit
, do it from a temporary staging branch - if you (or git) mess up, it's much easier to recover by just deleting the branch and starting overWhen svn dcommit
dies halfway through a large commit and you seem to have lost all of your history, do this:
How To Recover:
First, open .git/logs/HEAD
Find the hash of the commit that's the head of your git repo. Hopefully you remember the commit message and can figure it out, but it should be pretty obvious
Back in your now f-ed up working-dir:
git reset --hard <hash from log>
This gets your working dir back to where it was before you did a git- svn dcommit. Then:
git-svn rebase git-svn dcommit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With