22 May 2007
Git’s Notes On Git
Over the past few weeks I have been coming to grips with git-svn, and git in general. Two reasons in particular led me to jumping on the git bandwagon. First of all, although I like the simplicity of svn, I have ever increasing number of svn checkouts around, taking more of my diskspace than I am happy about; as it happens, git is much more efficient in disk usage than svn, and the savings I have made by moving my svn repos to git-svn have been significant.
The second reason, and probably the more significant one, is that git makes it much easier to work with multiple branches, in particular, to create private local branches with proper history tracking, in which I can work on all kinds of unstable features that I do not want to pollute the public repo with, yet that are sufficiently complex to benefit from being able to commit in small step, revert, etc. The git merge works extremely well (except for change logs, see below), so that keeping my local branches in sync with the remote repo has proved very easy.
Admittedly, the git learning curve is steep, especially if coming from a CVS / SVN background, as most of the git commands bear no resemblance to the cvs interface (not really surprising as git is quite different under the hood from either), and the man pages are of varying quality (and generally assume that you know how to use git). So, here are some git/git-svn notes for gits like me:
To set up a git repo on the top of a remote svn repository
See this helpful post.
To create a local branch from svn HEAD
‘git-checkout -b newbrach_name remotes/git-svn’
To switch between branches
‘git-checkout branchname’
To list branches / find which branch is currently active
‘git-branch’
To do ’svn update’
‘git-svn rebase’
Local commit
‘git-commit -m “commit messages”‘ (NB: you must add the files to include in the commit with git-add first, make sure to read man git-add).
Commit to the svn repo
‘git-svn dcommit’ This commits all outstanding local commits to the remote repo, one by one with the commit messages as originally passed to git-commit. If you would prefer to do just a single commit to the remote repo, you can generate a patch with git-diff, create a new branch, apply the patch, do local commit, then git-svn dcommit.
Fixing merging conflicts.
If there is merge conflict during ‘git-svn rebase’, the process stops indicating where the problem is; to fix it: * Edit the offending file(s) to resolve the problem, * ‘git-update-index file’, * ‘git rebase –continue’, (NB, not ‘git-svn rebase –continue’).
The git merging algorithm seems to have real problems with changes to change logs, so I usually modify the change log just before doing ‘git-svn dcommit’.
Reverting changes
- Committed changes: see ‘man git-revert’
- Staged uncommitted changes: see ‘man git-reset’ and the -i option in ‘man git-add’
- Unstaged changes: ‘git-checkout file’