1

On a rare occasion a git pull will cause an issue on our site and I need to quickly rewind the clock so the developer can fix the issue. I've tried git reset HEAD@{1} but that doesn't do the trick as some of the files are still changed. As though it only rolls back some files.

Is there a single command I can call to reliably revert files back before the most recent git pull command?

dcp3450
  • 10,959
  • 23
  • 58
  • 110
  • Does this answer your question? [How to undo a git pull?](https://stackoverflow.com/questions/5815448/how-to-undo-a-git-pull) – Ethan Furman Nov 03 '20 at 16:49

2 Answers2

9

Find the most recent commit you want to keep, and count how many commits appear after that one. For example, let's suppose that three new commits came in with your latest git pull and you want to nuke them. In this case you can use git reset --hard:

git reset --hard HEAD~3

Just replace 3 with however many commits you want to remove.

There is the lingering question of what you plan to do after this. Now the remote branch still will have those three unwanted commits. But assuming you fix the problem by making a new commit, you could avoid the issue of rewriting history.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

Are you simply doing

git reset HEAD@{1}

? If so, this uses --mixed mode as the default, which would explain why you're seeing changed files. My suspicion is that you should be using

git reset --hard HEAD@{1}

so that it resets your working tree too.

jbu
  • 15,831
  • 29
  • 82
  • 105