-2

By mistake I did a git reset HEAD~ in my branch. I see all my changed files on my local. I don't want to change anything. The branch is good as is.

What do I have to do?

meez
  • 3,783
  • 5
  • 37
  • 91
  • 1
    take a look at the reflog (`git reflog`) and then use the right commit id to do another `git reset`. – eftshift0 Nov 29 '22 at 12:09
  • 1
    `git reset "HEAD@{1}"` https://stackoverflow.com/a/5127681/7976758 (but do not use `--hard` as it removes local changes.) Found in https://stackoverflow.com/search?q=%5Bgit-reset%5D+undo – phd Nov 29 '22 at 12:27
  • @phd Why not just making this question a duplicate of the one you linked? It seems similar enough, but maybe there's something I missed? – Romain Valeri Nov 29 '22 at 13:19
  • 1
    @RomainValeri The option `--hard` (all over the the linked Q and As) is a rather dangerous one for an unprepared user. I'd like the OP to report success or comment why he's not satisfied. – phd Nov 29 '22 at 13:29

1 Answers1

0
  1. If you haven't done anything else, just do this command git reset --hard HEAD@{1}. If you've made other changes, do git reflog show to see which commit you want to revert back to. Then do git reset --hard XXX and put that commit ID in the XXX part.

  2. You then git push --force to make sure your remote branch reflects the change.

DonQuijote
  • 47
  • 8
  • 1
    Using `--hard` is unnecessary in the presented situation. Suggesting it makes the operation unnecessarily dangerous. See also the comments by @phd above. – j6t Nov 29 '22 at 20:53