How to remove all local files that were accidentally added to the git system

后端 未结 1 976
时光取名叫无心
时光取名叫无心 2020-12-22 13:26

I\'m new to the \"git\" system. I may have made a mistake and integrated all my local files into the \"git\" system.

I use \"vs code editor\" and discard all changes

1条回答
  •  温柔的废话
    2020-12-22 13:49

    When you say git init, you are doing two things:

    • You create a (normally invisible) .git folder in the current directory.

    • You place the current directory and all its subdirectories recursively under git control.

    So, if you whip out the Terminal and say

    % git init
    

    ...the current directory is your home folder, and that is where the .git folder is created, and now your home folder and all its contents at any depth have been placed under git control. Which is a really bad idea, putting your whole world under git control.

    Okay, so then you say

    % cd Desktop
    % git status
    

    Well, the Desktop folder is inside the home folder, and the home folder has the .git folder, so the Desktop folder is under git control, and the git status command works, and correctly reports, "Hey, I'm supposed to be controlling all these files and folders. What would you like me to do?"

    What you'd like it to do is nothing. You've made a silly mistake and you need to back it out. To do that, just delete the invisible .git folder you created earlier by mistake in your home directory. Done. Your world is no longer under git control.

    (The easiest way to do that, in a modern Mac system, is to press Command-Shift-Period, which makes invisible folders visible, so you can see the .git folder and drag it into the trash.)

    Now, if you also said git clean while your world was under git control, you may have deleted some of your stuff. And when I say deleted, I mean deleted. That stuff is absolutely irrevocably gone. If you use Time Machine or Carbon Copy Cloner or similar, you might have a backup elsewhere, but that has nothing to do with git. You told git to delete things and it obeyed.

    0 讨论(0)
提交回复
热议问题