Last Updated: August 01, 2023
·
1.552K
· squidbidness

Local non-compiling git save-points

After numerous times wishing to save some coding work that won't yet compile, but being a good boy and wishing to follow the rule of never pushing non-compiling work to a git repo (or any shared source control, for that matter), it finally dawned on me: USE git FOR LOCAL BRANCHES AND DON'T PUSH THEM TILL THEY COMPILE. Duh.

Now I can save snap-shots of my code whenever I need, even if they don't yet compile. But when everything is nice and working good, and it's time to push, it would be nasty to push the non-compiling incremental commits to the remote end, even if the overall result of the branch being pushed comes out okay. So, I found some useful tips on stackoverflow that show how to squash multiple commits into a single commit, using git's interactive rebase. See below:

http://stackoverflow.com/a/5668050/1286986

The linked to doc in the above answer is useful background, with more detail:

http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

Then there is another useful answer for how to handle the case where you actually pushed the should-have-been-squashed commits to a remote repo. The short answer is: DON'T, if there's any possibility someone else has already pulled those commits. But if it's not too late:

http://stackoverflow.com/questions/5667884/how-to-squash-commits-in-git-after-they-have-been-pushed

2 Responses
Add your response

Just push a wip/ tree, (ie, wip/features/some_new_feature) This way you have a backup and some exposure to what you're working on, but noone in their right mind would base work ona wip/ branch.

over 1 year ago ·

@richoh I hadn't been aware of the wip convention. Very handy.

over 1 year ago ·