- git rebase -i HEAD~X - this allows you to merge interactively several commits
- then fixup OR pick OR reword AND push --force
- git reset --hard HEAD~X - this rollbacks the index back to X commits (check git status before doing this. Commit first)
- commit again using just one commit
- git reset --hard COMMIT_ID - this rollbacks the index back to the commit_id
Last active
November 30, 2023 21:28
-
-
Save alebaffa/cd61f177a79a4d857bcc55ba7c535f3a to your computer and use it in GitHub Desktop.
Git squash alternatives
Does the second method work when changes are already pushed to the remote?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the reminder about interactive rebasing
rebase -i
. 😄A quick tip for the others finding this gist when searching for
alternative to git squash
:I would recommend using
--keep
instead of--hard
most of the time, since the first keeps your working directory as-is from what I gather, it does not make you lose any work.https://git-scm.com/docs/git-reset#Documentation/git-reset.txt---keep
A bit like the difference between
--force-with-lease
and plain--force
, you won't be losing any work when using the first one, worse case, it will prevent the operation if it could be destructive.https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-force-with-lease