I just did a pull from github and pulled from the wrong github repository into my project. How do I undo this?
Thanks!
One way to do this
$ git reset --hard latest-good-commit-hash
Use git log --all
(or more graphically, use gitk --all
) to see the commit history
Try git reflog
. Reflog allows you to undo almost any operation.
Something like this
git reset --hard HEAD@{1}
However, if you had dirty working copy, it will erase all your changes, so beware.
git reset --hard HEAD^
This command resets your branch to the previous commit, that is the commit before the merge commit, which is the one you want to undo. Your work will be left untouched.
Remember that everything that has been commited is still there as loose objects and you can always use git reflog to revert to any version HEAD has pointed to before. This is why it's so important to commit often with git, you can undo all changes you have done with ease.