I’ve been working with Git and Subversion together for some while, and I’ve been improving my work flow as I use it. Here’s the latest things I’ve worked out.
Stash popping with a dirty files
I use the stash command pretty frequently — often when I’m just working with a design but want to try something different and don’t want to play around with rebasing a commits — so I like my changes but want to put merge the code I had stashed. If you try:
$ git stash pop
You’ll get the error about working with dirty files. In order to remedy this, I fake it out, by pretending to want to add to the commit:
$ git add [files_i_changed]
Then, I do the stash pop and then reset so I don’t accidentally commit the code until I’m ready.
$ git reset HEAD
Appending commits for one commit to Subversion
A particular strength of Git is the ability to do multiple commits without sending everything to the server. (Okay, that’s the strength of any DVCS.) I usually like to send it all in one Subversion commit but I still want to keep a log of all my git commits, here is what I do. First, I’m working from a local branch that has all my git commits called ‘local_commits_for_issue_12345′.
Now, I will need to checkout the remote branch or the trunk that I want to commit to:
$ git checkout remotes/[branch or trunk]
And make a branch:
$ git checkout -b [some_new_remote_branch_name]
Then I merge:
$ git merge local_commits_for_issue_12345 --no-commit
Note, the no-commit part of the merge. Basically, Git will merge the code, and if it merges “successfully”, it will gracefully “fail” leaving the files that it merge in the filesystem until you do a git add and git commit and then git svn dcommit to send to Subversion. If it fails to merge successfully, well, you have to fix it like any other failed merge. As a side note, if you don’t include the no-commit, it’ll automatically commit the changes from your local branch.