Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Commit Undo

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).

like image 590
Drei Avatar asked Apr 29 '18 22:04

Drei


2 Answers

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)

like image 166
Drei Avatar answered Sep 21 '22 22:09

Drei


  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

like image 33
Ashish Singh Avatar answered Sep 23 '22 22:09

Ashish Singh