I made some source changes to lint my code. I did not run unit tests, and later I found that a large commit broke the code. How do I go back and find out which code change in a number of files broke the tests?
I could:
- diff the working (earlier) commit against the breaking (later) commit
- save the result in a patch file
- patch/test cycle
- apply parts of the patch file to the earlier commit
- run the tests
I am hoping git has something less manual than this.
There’s a decent way to do this using the ability of
git-stashto not only stash away and reapply changes, but also the state of the index. It goes something like this:Using stashes and testing as you go along has the advantage that if you manage to pick a subset of the changes which simply breaks the build, you can just pop the stash back off, and try again.
You could do something similar to split up the commit into many, then run
git bisecton it, but often that’s more work, since it’s more difficult to know how to split things up without testing as you go along.Of course, now you know that you should make smaller commits. But I don’t always do it right the first time either!