Git rollback 1 pull

git reset --hard HEAD^1 will take you back one commit from what you pulled. If you want it back to the state it was in before you pulled, use git reset --hard HEAD@{1}. The @{1} tracks where the head was at before the last operation that changed it in your local repo, so it will go back several commits if several were pushed before you did your pull. Also see git reflog to show the entire list.


There is another way to discard last pull

git reset --keep HEAD@{1}

git reset HEAD^ should take you to the previous commit. See here for more info.


In this case it can make sense to use a branch, which can be easily removed or merged upon failure or success. This will help you keep track of what is new, and make things cleaner if you have more complicated cases than "just remove last commit" (especially since you want to do that with a script). So on your server:

git fetch --all           # fetch new commits from remote
git checkout -b testing   # create and switch to branch 'testing'
git merge origin/master   # merge new commits from remote branch master
                          # (in branch 'testing')

... then test stuff... if success:

git checkout master       # switch back to master
git merge testing

and upon failure:

git checkout master
git branch -D testing     # remove testing branch

But anyway... It your only point is to remove last commit, you can use git reset as pointed out by Josh.


I've used below command to revert the last commit

git merge --abort