VS Code Commit Undo

12,518

Solution 1

The answer is really quite simple after looking into what "undo" actually does.

VS Code "Undo Last Commit" simply runs git reset HEAD~. These actions are in the output if you open up the "GIT" tab. The solution however can be found by looking at what was recorded by running git reflog and then manually running the git reset to before VS Code ran it. here is a better reference.

(I'll also leave this up in case someone else has the same worrisome mistake in VS Code)

Solution 2

  1. go to three dots (...) on the upper right corner of the vscode
  2. go to commit
  3. select undo last commit

See below image:
enter image description here

Share:
12,518
Drei
Author by

Drei

By day I am a simple school kid struggling like the rest of us to keep up while juggling my time consuming passion. My passion is code. While I don't let it consume me, I dedicate myself to challenge to myself and the bring code norms that suggest my work should be average. Instead, I hold myself to dangerously high standards and constantly strive to make my products better. Code has therefore taught me that that sometimes the best option is scrap it all and start from scratch.

Updated on June 17, 2022

Comments

  • Drei
    Drei almost 2 years

    I have quite a few changes that I would like to commit to new a branch but I've accidentally been working on the master in VS Code. This wouldn't have been an issue until I have accidentally clicked "Undo Last Commit" (twice, not once) because I almost published to master.

    I am now especially worried that my progress will be overwritten when trying to commit my changes because VS Code tells me it would require me to first "pull." (I assume overwriting my files).

    Sorry if I am under-informed on my situation, but the thought of losing my progress scares me too much to just start "trying" things as I always do (that's what got me here in the first place).

  • Abdul Rahman Kayali
    Abdul Rahman Kayali over 2 years
    Mostly the command executed in the background will have the --soft flag like this: git reset --soft HEAD~
  • c-shubh
    c-shubh over 2 years
    For reference: Relevant Function: github.com/microsoft/vscode/blob/… Relevant line: github.com/microsoft/vscode/blob/…