Skip to content

Instantly share code, notes, and snippets.

@SheldonWangRJT
Last active February 14, 2018 13:53
Show Gist options
  • Save SheldonWangRJT/c13a854c20504c35e577e7cae7b71438 to your computer and use it in GitHub Desktop.
Save SheldonWangRJT/c13a854c20504c35e577e7cae7b71438 to your computer and use it in GitHub Desktop.
Git Cancel Commit Before Push
#iOSBySheldon
Sometimes, we have committed something and then we regret and don't want to push it anymore. In case of this, we can discard our commit, which is better done in terminal, I mean, SourceTree is limited sometime.
There are multiple ways to do this, you can rebase, you can reset, today, I will use reset.
1. Soft reset
$ git reset --soft HEAD^
2. Hard reset
$ git reset --hard HEAD~
The only difference is that for soft reset, you commit will come back and stay in the staging phase. However, using hard reset, you commit will be gone completely.
Therefore, after soft reset, you just need to discard your changes and everything will be alright.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment