hieuhtr / Blog

Don’t be lazy. Don’t make excuses. No one cares. Work fucking harder.
Other
6 stars 2 forks source link

Remove latest commit in local git repo #62

Open hieuhtr opened 7 years ago

hieuhtr commented 7 years ago

Problem:

$ git add .
$ git commit -m "abc xyz"
# dafug... wrong file... useless commit ... need to revert/remove this commit

Solution:

First, remove the commit on your local repository. You can do this using git rebase -i.

For example, if it's your last commit, you can do git rebase -i HEAD~2 and delete the second line within the editor window that pops up --> save this file

Then, force push to GitHub by using git push origin +branchName

Reference:

https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github/448929#448929