-1

I just ran this command:

 git reset origin/dev -- package-lock.json 

but I want to do undo it, I want to go back to:

 git reset HEAD -- package-lock.json 

but I think it might be too late to go back to HEAD...how do I undo the original command?

Maybe:

 git reset HEAD^ -- package-lock.json 

?

Update: I think I meant to do git checkout origin/dev -- package-lock.json, not git reset.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

2

git reset commit -- path means: copy file path from commit into index.

You cannot undo this, as it overwrites whatever file was in the index for that path.

Fortunately, you rarely ever need to undo this, because the copy that was in the index is probably also somewhere else too. If so, just copy that copy into the index. Usually, the copy of any file that is in the index is itself a copy of some other file: either a copy of a committed file, extracted via git checkout, or a copy of a work-tree file, added via git add.

If the copy that was in the index does not exist anywhere else, you are out of luck. But this generally only happens with git add --patch or git reset --patch.

Update: I think I meant to do git checkout origin/dev -- package-lock.json

This means: copy file package-lock.json from the commit identified by origin/dev into the index, and then copy the index version into the work-tree. As with git reset, this overwrites whatever was in the index before, and that part cannot be undone. On successfully overwriting the index version, it also extracts the file into the work-tree, overwriting whatever was in the work-tree. This, too, cannot be undone—and it's less likely that you have a copy of what you had in the work-tree earlier. So be even more careful with this kind of git checkout than you are with the above kind of git reset.

In any case, if that is what you meant, you can just do it now, overwriting whatever you stuck in the index earlier and also overwriting the work-tree copy.

torek
  • 448,244
  • 59
  • 642
  • 775