Is there any way to revert or undo git pull so that my source/repos will come to old state that was before doing git pull ? I want to do this because it merged some files which I didn't want to do so, but only merge other remaining files. So, I want to get those files back, is that possible?
EDIT: I want to undo git merge for clarification. After seeing some answers, I did this
git reflog
bb3139b... HEAD@{0}: pull : Fast forward
01b34fa... HEAD@{1}: clone: from ...name...
Now, what should I do ? Doing git reset --hard
is OK ? I don't want to screw it again, so asking for detailed steps ?
git reset --hard 01b34fa
, in this case you could have donegit reset --hard HEAD^
which resets to one commit before the HEAD. – Ceresgit reflog
will show everything what have been done with git. There is a concern thatgit reset --hard [sha1 of something from reflog]
will revert everything what is shown inreflog
, which sometimes are not goal, eg. you want to revert merge on master branch pulled from origin with bad data (happens), and after that merge you have worked on other branches.reflog
will show every chage on other branches. Butgit checkout master
andgit reset --hard [SH1 of commit on master branch just before merge]
will reset only current master branch removing pulled merge from origin. – Loraleeloraliegit pull
habit. Always usegit fetch
and then intelligently decide on what to do next. – Chidestergit reset --hard HEAD~1
– Bayou