[clug] "git" hints?
Alex Satrapa
grail at goldweb.com.au
Thu Nov 13 03:51:40 GMT 2008
Say I'm working on some test-driven development. Let's also say that I
want the policy for the project to be that all commits to the "main"
repository must pass all tests.
So locally, I write a test, which I expect to write code to support.
Now I have a test that fails. This can't go to the main repository,
and I don't necessarily want to leave this committed to my repository
since I know the guy next to me has been fetching every change I make
like there's no tomorrow and he'll run the tests and spend hours
trying to figure out what broke when it's simply the case that the
test appeared before any code existed to make it pass.
While I'm trying to implement the (extremely complex) code that causes
that test to pass, I happen to find an interesting article on Django
unit testing that suggests using a different test framework. So for a
moment, I want to save the code I'm working on which doesn't quite
make the test pass, but I'm sure I'm almost there. I want to be able
to get rid of both the test I wrote and the primordial class + methods
that exist so far - they don't work, and I just want to stash them
away somewhere to come back to later. I don't want to lose them forever.
Here's one thing I could do:
git commit -m "Implementation in progress"
-> commit d3adb33f
git checkout HEAD^ . # rewind to before the changes I just
saved
git checkout -b FancyNewFeature # switch to a new branch for fiddling
This means that my commit d3adb33f is still in the repository and I
can return to it at any time, so my work is not lost:
git checkout master
... but I'm sure there's a better way. Any suggestions?
Also, how much trouble am I going to get myself into with this shell
function:
switch () {
if [ -z "$1" ]
then
git branch
else
git checkout $1
fi
}
This is used thus:
[alex at here]% switch
FancyNewFeature
*master
[alex at here]% switch FancyNewFeature
Switched to branch "FancyNewFeature"
Alex
More information about the linux
mailing list