Wednesday, April 20, 2011

How to git svn dcommit with uncommited changes

If you want to send your commits to a svn backend, you can do this with:

> git svn dcommit

Sometimes git ends with the error messge 'file.xy: needs update'. This happens if you have uncommited changes in your working directory. But often you won't commit these changes to the repository yet. A workaround would be the following:

> git stash
> git stash list # if you want to check the stashed changes
> git svn rebase # get the remote changes
> git svn dcommit
> git stash apply
> git stash drop # clean up the stash list if everything went fine
A shortcut for stash apply + stash drop also exists:
> git stash pop
I created a shortcut for this:
> git alias.svn-update '!git stash && git svn rebase && git stash pop'
> git svn-update