Suppose I have three commits
A --> B' --> B
Commit B'
represents an intermediate state, where work is unfinished and tests aren't passing. I may have made commit B'
in order to switch from working on my home machine to my work machine.
Let's say I'm on a topic branch that no one is looking at but me. But all three commits are in the remote, otherwise I couldn't use B'
to pass changes from one machine to another.
If I do git rebase -i <commit-before-A>
(or if A
is the first commit, then git rebase i --root
), and I choose to fixup
or squash
commit B'
, then the changes in B'
will be folded into commit A
.
But this isn't appropriate. I want commits A
and B
to to represent reasonable checkpoints in the work, where changes aren't in a half-assed state that no one would understand but me. If I fixup
the B'
commit, then that will leave commit A
with the half-baked changes that B'
used to have. I want commit B'
to be folded into B
, since B'
represented intermediate work towards commit B
.
Possible solutions:
1a. Just leave commit B'
and name it "dummy commit" so no one pays attention to it. It's on my topic branch (even though it's pushed to remote), so who cares.
1b. If I think people might potentially look at my current topic branch and judge me for being unprofessional, give B'
its own branch that I'm sure no one cares about, then as soon as B
is ready, commit it and merge it back into the original branch, then delete the temporary branch. So it looks like
BRANCH DELETED
B' --> B''
/ \
A ---------> B
BRANCH REMAINING
- Get rid of
B'
before I make commitB
. So ifB'
was made in order to switch machines, once I get to the other machine, immediatelygit reset --soft
, then once I've finished changes, make commitB
, thengit push --force
to the remote, then if and when I go back to the first machine, usegit pull --force
. It's unfortunate to "rewrite history" this way, and using--force
quite so often seems like a dangerous habit. drop
commitB'
instead ofsquash
orfixup
. Git seems to not treat this very intelligently and require merge resolutions even whenA --> B' --> B
are evidently fast-forward changes. Again, you're rewriting history, and--force
will be required multiple times.- If the two machines are on the same network, use file sharing instead. This seems gross to me and not flexible.
- Do one of these and live with it; it's a matter of taste and you can't please everyone.
Bear in mind the purpose of this question isn't to start an argument on a matter of taste; it's to uncover pros and cons I haven't thought of, or expose me to options I haven't thought of.
Related posts: