0

I forgot to commit on the directory where I was working and then I checkout to the previous commit and now I want to back to the directory where I used to work. What can i do ?

shihar
  • 48
  • 7
  • If you mean that you checkout on the other branch without commiting the changes, then those changes will be merge to the newly checkout branch. Going back to the previous branch will do the same. – Forbidden Dec 29 '21 at 07:45

1 Answers1

1

If your checkout of the previous version somehow deleted your folder, which was not added/committed, then you would need to rely on a file recovery utility, as detailed in "Can I restore deleted files (undo a git clean -fdx)?", or on your IDE. Some of them keep a local history (IntelliJ IDEA, VSCode through an extension, ...): you might get back some of your files content that way.

In the end, it depends on the exact git checkout command you did, considering this command can update files and/or branches.
That is why it is recommanded to use git switch (branch only) or git restore (files only), instead of git checkout.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250