The way I go about it is by typing git status
, which allows us to verify the branch we're currently on, followed by:
git log
Then, you'll see something like this:
commit aa09a82fb69af2d1aebde51d71514f7a03c3a692
Author: User <user@useremail.com>
Date: Fri Nov 4 15:36:22 2016 -0400
Fix issue with vertical scroll being forced
commit 411771837efe3ed555395e77fd35105a500ab758
Author: User <user@useremail.com>
Date: Thu Nov 3 15:50:42 2016 -0400
Add user notifications
commit f43b262f4e02b5a7268280e1230d44e36d1e547b
Author: User <user@useremail.com>
Date: Thu Nov 3 12:11:00 2016 -0400
All your base are belong to us
So, this tells us that commit aa09a82f
is your last one, and commit 41177183
is the one before it, then:
git reset --hard 41177183
...brings us back to that commit, retaining the remote backup. With another git status
to make sure that everything is all set for the double push (I'm personally a bit obsessive compulsive about verifying my current branch, especially when multitasking):
git push origin :<branch_name>
git push origin <branch_name>
At this point, you should be all set, but it's always good to follow that up with:
git fetch --all --prune
git branch -av
...which cleans up your branch list and shows you both local and remote to compare the commit messages.
Also, if working with a team, make sure that they're aware of this before moving forward. You don't want them to pull or push the branch on their end before you remove the last commit and push.