Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to restore a set of unpushed Git commits in VSCode?

I have been using Git version control system in cooperation with the VSCode 1.51.0. I have following scenario:

  1. I have made several changes and I have created a separate commit for each of them (but I haven’t pushed none of the commits)
  2. I have accidentally invoked the git checkout command and I have switched to another branch.

After that it seems to me that all my unpushed commits have been lost. Please can you tell me whether there is any method to restore them somehow? Thanks in advance for any ideas.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Don’t panic, nothing is lost.

Unlike some version control systems, git is designed to be completely decentralised – pushing to a remote server is completely optional. Your local working copy is a complete clone of the repository on its own, and can be used entirely without any internet access, or even without having a copy anywhere else. Switching branch without pushing is entirely normal and nothing to worry about.

When you made your new commits, you had a particular local branch checked out, and you added your commits to that branch. All you need to know is the name of that branch, and you will see that all the commits are still there: git log my-branch-name will show them, git checkout my-branch-name will check out the branch including them, and you can push them up to the remote server as normal.

In the unlikely case that you don’t know the branch name, the commits will still exist somewhere. See How can I recover a lost commit?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading