lundi 24 septembre 2007

Unusual Git usage : temporary commit into a local SVN checkout

I really love Git, the distributed source code management designed by Linus Torvald. It is VERY easy to setup a new local repository (just type git init in the root of your working directory). I do it all the time, even for a simple bash script creation. Even for the simple text files I use as TODO lists.

A few days ago, I add to work offline in an old SVN checkout. I wish I could have used git-svn but it was an old checkout, and I was offline now. So much for git-svn for now...

I had to find something to be able to undo my changes while I was offline. So why not try Git in a local SVN checkout ? After all, the only thing that Git does is to create a .git file, it does not modify the local files if I don't want to.

So, at the root of my SVN checkout directory :
git init
Then, I must hide the .svn metadata directory, so I modify .git/info/exclude and I add the line :
.svn


Now Git will ignore the .svn directories and I can type :
git add .
git commit

Now at least I can regularly commit my changes into Git and go back in time if
I badly break my unit tests during my TDD session. Of course when I'll be back online
and I'll commit into the SVN repository I'll lose the commit history in Git, but as I
was offline anyway, at least I could work with a safety net.

Even used in this unusual way, Git is still useful.

2 commentaires:

Mathias a dit…

You could replace git with hg and the article would stay true (except that its .hg/... and .hgignore). ;)
I use hg like you use git. These new distributed SCMs are really awesome. HG is mostly written in python (except for performance critical parts) and therefore is ultra portable and even works natively under Windows. And it does not need repacks.

NetBeans has integrated hg support! (Though it was a bit incomplete the last time I checked.) And of course there is TortoiseHG for Windows and Linux.

Oh, and another thing I do: I have a hg repo on my USB stick and I've installed hg in the home directory of my profile at university. This way I can easily keep the files on my USB stick and on my home PC in sync without a need to worry about lost updates. ;)

Stephane a dit…

Yes, it seems that the support for most distributed SCM (Git,Hg...) in most IDE is currently pretty weak... I guess these are still tools for command line only users.

Thanks for your comment, I'll try hg.