0

I am fairly new to Visual Studio Code(VScode) and Git, and now I have a problem about "Source Control" in VScode. Please hlep me, thank you!

I used VScode to connect my server(Ubuntu 20.04.2 LTS) remotely via using local Window10, and everything was fine this afternoon(03/24 2022), but next I selected Source Control and clicked the button in the VScode.Picture-1

Then I clicked Initialize Repositor, and now the path is /root.Picture-2

And then things started to go bad and suddenly there was "7K+" in source control.Picture-3

I would like to discard this changes but I failed to do it, and I want to cancel this changes and go back to the previous state. I need your help!

In addition to the operations described above, I was going to add the .gitignore file, but it didn't solve the problem completely (just 7K+ --> 6K)

Yang
  • 345
  • 1
  • 3
  • 5
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+init+home – phd Mar 24 '22 at 17:20
  • You initialized a `.git` repository in a wrong directory (in your $HOME, actually, most probably `/root`). Simple remote it: `rm -rf /root/.git` – phd Mar 24 '22 at 17:21

1 Answers1

1

So to summarize, you had a random folder with code inside and you created a git repo inside it (paragraph 3). This then showed you every file in that folder as "changed" (paragraph 4).

So far everything is fine, that's how git works. You have an empty repository and a folder full of 7k files. All those files are "changed" (specifically, new) from the empty repository you have created. The next step is to make a commit to push the changes in your repository.

I would like to discard this changes but I failed to do it

The changes you mention here is every single file you have. If you go through with this (git reset), you will delete every single file. That sounds particularly insane to me, but is in line with the rest of the question, so I'll just make an assumption that this might not be what you want. If I'm right, keep reading.

I want to cancel this changes and go back to the previous state

Again, the "previous state" is literally an empty folder. If this is what you want, either use git reset to have git delete your files, or delete them yourself.

In addition to the operations described above, I was going to add the .gitignore file, but [...]

Add it now, rather than later. And there is no "the" .gitignore file, you have to write one for your specific folder. Start by going down the list of modified files and seeing what shouldn't be there, and add their patterns to your .gitignore. Or just use a pre-built one for your specific project type (node.js?)

Blindy
  • 65,249
  • 10
  • 91
  • 131