Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
2 views
in DevOps and Agile by (29.3k points)

Is there any way to revert or undo git pull so that my source/repos will come to the 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? 

I want to undo git merge for clarification. After some research, 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?

1 Answer

+5 votes
by (50.2k points)
edited by

Git pull will do two things one is git fetch and the other one is a git merge so in order to undo a git pull first you need to undo the merge 

And that can be achieved by using git reset --hard and then using git reflog you can find SHA-1 of the previous state and you can reset it. And one more command which will be more useful 

git reset --hard HEAD@{“”} 

Thus, you can undo a git pull and bring repos to the old state.

For more git commands like this please go through the following tutorial that will help you understand the git



If you wish to learn more about it, you can also enroll in Git Training.
Undo git pull, how to bring repos to old state
Intellipaat-community
by (29.3k points)
thanks, but this command deletes my local files that are not committed yet.
by (19.4k points)
yes, --hard will delete the untracked changes.
for more details: https://git-scm.com/docs/git-reset#Documentation/git-reset.txt---hard

Browse Categories

...