When you want to keep a tidy commit history on a branch you own, the safe-ish recipe is: stash a temporary branch as a backup (git branch temp_backup), git reset --hard <target> your current branch back to where you want it, git cherry-pick the commits you want to keep on top, then git push --force. The temp branch is your seat belt — keep it around for a day or two until you're sure nothing went sideways.
The full post walks through that flow with the --hard/--soft/--mixed reset variants, plus the obligatory caveat: force pushing is fine on solo branches and a great way to lose other people's work on shared ones. Coordinate before doing it on anything anyone else has pulled.
Originally published at andreasbergstrom.dev — read the full post there.
Top comments (0)