Debug School

rakesh kumar
rakesh kumar

Posted on

how to remove last pull in git

git-rollback-1-pull
git-how-to-undo-a-git-pull

Error:

Auto-merging push/tripshow.blade.php
CONFLICT (content): Merge conflict in push/tripshow.blade.php
Automatic merge failed; fix conflicts and then commit the result.
Enter fullscreen mode Exit fullscreen mode

Solution
How to undo a git pull
Sponsor

Have you ever been working on a project, ran a git pull only to realise you’ve majorly messed up? Now all your code has been overwritten with whatever was in your remote repository - and sometimes this isn’t what you want. In times like this, it’s easy to panic, but fortunately there are a few ways to revert your code back to its old state and undo the git pull.

First things first, make a copy of your project in case you cause things to get worse. Also note that these commands will cause you to lose all uncomitted changes - so a backup can help you save that stuff before you continue. At least then, you’ll have the version you currently have. After you’ve done this backup, you’ll want to get a list of all your commit history. You can do this by running git reflog:

git reflog
Enter fullscreen mode Exit fullscreen mode

How to undo a git pull

Have you ever been working on a project, ran a git pull only to realise you’ve majorly messed up? Now all your code has been overwritten with whatever was in your remote repository - and sometimes this isn’t what you want. In times like this, it’s easy to panic, but fortunately there are a few ways to revert your code back to its old state and undo the git pull.

First things first, make a copy of your project in case you cause things to get worse. Also note that these commands will cause you to lose all uncomitted changes - so a backup can help you save that stuff before you continue. At least then, you’ll have the version you currently have. After you’ve done this backup, you’ll want to get a list of all your commit history. You can do this by running git reflog:

git reflog
Enter fullscreen mode Exit fullscreen mode

This will generate a list that looks like this:

648e314 (HEAD -> master, origin/master) HEAD@{0}: commit: Design refresh
b0168ee HEAD@{1}: commit: Minor CSS tweaks
514a02f HEAD@{2}: commit: Fixed extra curly brace
b432ba7 HEAD@{3}: commit: fixed border-radius
a707d13 HEAD@{4}: commit: fixed image border-radius
abf89a3 HEAD@{5}: commit: updated look and feel
Enter fullscreen mode Exit fullscreen mode

Select the version you want to revert to. For example, if I wanted to revert to ‘Minor CSS tweaks’, I’d select the ID b0168ee. Next, run the following command to revert your repository to that

git reset --hard b0168ee
Enter fullscreen mode Exit fullscreen mode
git reset --hard HEAD^1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)