Search code examples
gitgit-commitgit-pushgit-pull

How to un-commit all un-pushed git commits without losing the changes


Is there any way to undo all un-pushed commits (I made 3 commits to the wrong branch without pushing) without losing the changes?


Solution

  • You can use git reset to get back to previous commits.

    Make sure to use the --mixed option, so it keeps your changes but removes the commits:

    git reset --mixed HEAD~3