The questions I've seen for undoing a git pull a slightly different to mine.
This is what I've done:
There is a project in directory A
(not a repo). I initialized a repository in it, added the files, but did not commit anything. Then I pulled from repository B, which overwrote a bunch of my staged files.
I was under the impression I could use git reset --hard
to undo the merge. Of course that just checked out the HEAD of the commits I had just pulled in.
I should have branched and commited something before I did this pull, hindsight is nice. Is there some way I can get my old unstaged files back?
A git pull
is the same as git fetch
+ git merge
. It is the merge step that overwrote your changes. To revert to the state before the merge, use git log
to find your latest commit and then use git reset --hard 1234abcd
where 1234abcd is the hash of the desired commit.
Note that after the reset git pull
will merge the changes again. To revert the changes for good, use git revert
which will create an additional commit reversing the changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With