1

I'm a bit new at this, so bear with me.

I saved a .js file in my user just so I could run it's output in Terminal. This file appears to have created changes in all my projects. I feel a bit foolish.

How can I discard all these changes at once? I tried doing this in VS Code, but when I click the Discard All Changes option, VS Code says that might delete one or more files (see attached screenshot). Naturally, I feel this might be a bad idea.

Then I tried get reset--hard, git checkout -f, and git reset --hard HEAD^ on my user through command lines in Terminal, but I always get the same error message:

fatal: not a git repository (or any of the parent directories): .git

I don't know how to now get around the issue.

You can find images of the problem attached:

File changes and terminal message

VS Code message with all files which will be deleted if I discard changes

Thank you in advance for any and all help!

  • 4
    Might be a time to learn using git from command line. Confusing situations sre sometimes much less confusing when you examine them without an extra GUI layer in between. – hyde Oct 15 '22 at 14:26
  • 1
    Also, VS Code is a bit [notorious](https://stackoverflow.com/questions/43541167/how-do-you-undo-discard-all-changes-in-vs-code-git) when it comes to using *git* from it... – hyde Oct 15 '22 at 14:28
  • Make sure you use the terminal inside the project folder – mousetail Oct 15 '22 at 14:39
  • 1
    just typing random `git` commands and hoping one will do what you want is asking for disaster. `get reset --hard` is a good one if you don't know what you're doing and what the command does, you have a git repo, only you don't know where it is – rioV8 Oct 15 '22 at 14:54
  • 1
    Note that `fatal: not a git repository (or any of the parent directories): .git` means *you are not yet using Git*. You might want to start by experimenting with Git alone (no GUI, as @hyde suggested) on something of no value, by creating an empty folder, moving into it, running `git init`, creating a simple file or two such as "readme" and "main.js", `git add readme main.js`, and `git commit` to make your first commit. Then find a good Git tutorial (unfortunately this is hard, there are a lot of bad ones)... – torek Oct 15 '22 at 21:18
  • at the git-scm site is a good book for download – rioV8 Oct 16 '22 at 09:30
  • I think I now understand the issue a lot better. All y'all have been extraordinarily kind for helping out with this matter. Thank you! I've evidently quite a bit to study and catch up on regarding git. – Rafael Kasinski Oct 16 '22 at 17:51

1 Answers1

2

You might have a Git repository in the aula-matheus folder, but you did cd .. and went in the parent folder of that repository.

There is no Git repository in that parent folder itself, only in aula-matheus: if you want to execute any git command, you need to be in that folder.

Also, you can execute those same operation using VSCode Git integration, and see more with the VSCode GitLens extension.

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