Undo Git mistakes

Squash your last few commits into one

Tidy several small commits into a single one before you share your branch.

Fill these in once
  1. Undo the last few commits but keep all the changes
    Terminal
    git reset --soft HEAD~3
  2. Commit them again as one
    Terminal
    git commit -m "Add the login page"
  3. Already pushed? Update GitHub
    Terminal
    git push --force-with-lease

    Only on your own branches.

Check it worked

  1. See the single commit
    Terminal
    git log --oneline -5
  1. Undo the last few commits but keep all the changes
    Terminal · Ubuntu / Debian
    git reset --soft HEAD~3
  2. Commit them again as one
    Terminal · Ubuntu / Debian
    git commit -m "Add the login page"
  3. Already pushed? Update GitHub
    Terminal · Ubuntu / Debian
    git push --force-with-lease

    Only on your own branches.

Check it worked

  1. See the single commit
    Terminal · Ubuntu / Debian
    git log --oneline -5
  1. Undo the last few commits but keep all the changes
    PowerShell
    git reset --soft HEAD~3
  2. Commit them again as one
    PowerShell
    git commit -m "Add the login page"
  3. Already pushed? Update GitHub
    PowerShell
    git push --force-with-lease

    Only on your own branches.

Check it worked

  1. See the single commit
    PowerShell
    git log --oneline -5