There is a problem which I face using Git with Github. When I was committed the wrong commit on my Master Branch. I find the solution from Stackoverflow where most of Git users provide a useful answers I’ve share best answers on Blog.
There are many ways to undo your last commit in Git. One you can use advanced tools such as git-extras to Undo you last commit. The second way to use Git rebase or SOFT and HARD Reset~ commands.
You can find these commands form Git Official Documentation.
Some Answers from Stackoverflow:
Undo and Redo the Commit
$ git commit -m "Something terribly misguided" (1) $ git reset HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit -c ORIG_HEAD (5)
- This is what you want to undo
- This leaves your working tree (the state of your files on disk) unchanged but undoes the commit and leaves the changes you committed unstaged (so they’ll appear as “Changes not staged for commit” in
git statusand you’ll need to add them again before committing). If you only want to add more changes to the previous commit, or change the commit message1, you could use
git reset --soft HEAD~instead, which is like
git reset HEAD~but leaves your existing changes staged.
- Make corrections to working tree files.
git addanything that you want to include in your new commit.
- Commit the changes, reusing the old commit message.
resetcopied the old head to
-c ORIG_HEADwill open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the
1 Note, however, that you don’t need to reset to an earlier commit if you just made a mistake in your commit message. The easier option is to
git reset(to unstage any changes you’ve made since) and then
git commit --amend, which will open your default commit message editor pre-populated with the last commit message.
Read More & Reference : http://stackoverflow.com/questions/927358/how-to-undo-last-commits-in-git