如何删除所有意外添加到git系统的本地文件 [英] How to remove all local files that were accidentally added to the git system

查看:81
本文介绍了如何删除所有意外添加到git系统的本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是"git"系统的新手.我可能犯了一个错误,并将我所有的本地文件都集成到了"git"系统中.

当我说以下错误:Git: fatal: You are on a branch yet to be born时,我使用"vs代码编辑器"并放弃所有更改.

这是我在终端中使用"git status"命令时的样子:

warning: could not open directory '.Trash/': Operation not permitted
On branch master

No commits yet

Untracked files:
  (use "git add <file>..."
    to include in what will be committed)
  .. / .npm /
  .. / .viminfo
  .. / .vscode /
  .. / .zsh_history
  .. / Applications /
  . /
  .. / Documents /
  .. / Downloads /
  .. / Library /
  .. / Movies /
  .. / Music /
  .. / Pictures /
  .. / Public /

  nothing added to commit but untracked files present(use "git add"
    to track)

请不要以为我是来这里寻求解决方案的.我非常努力.我什至在这里也仔细阅读过这些文章.如何从当前的Git工作树中删除本地(未跟踪)文件.

git cleangit reset命令,例如我尝试但失败的命令.我试图找出我所缺少的.我不想使用错误的命令并破坏一切.如果您能在帮助时解释一下,我会知道的,我会很高兴的.谢谢你.

解决方案

您说git init时,您在做两件事:

  • 您将在当前目录中创建一个(通常是不可见的) .git 文件夹.

  • 您将当前目录及其所有子目录递归置于git控制之下.

所以,如果您拨出终端然后说

% git init

...当前目录是您的主文件夹,即创建 .git 文件夹的位置,现在,您的主文件夹及其所有深度的所有内容都已置于git的控制之下.将您的整个世界置于git的控制之下,这是一个非常糟糕的主意.

好的,那么你说

% cd Desktop
% git status

好吧,Desktop文件夹位于home文件夹内,并且home文件夹具有 .git 文件夹,因此Desktop文件夹处于git控制之下,并且git status命令可以正常运行报告说:嘿,我应该控制所有这些文件和文件夹.您要我做什么?"

您想要做的是什么都没有.您犯了一个愚蠢的错误,需要予以解决.为此,只需删除您先前在主目录中错误创建的不可见的 .git 文件夹.完毕.您的世界不再受git控制.

(在现代Mac系统中,最简单的方法是按Command-Shift-Period,使不可见的文件夹可见,因此您可以看到 .git 文件夹并将其拖动扔进垃圾桶.)

现在,如果您在世界处于git控制之下时也说了git clean,则您可能已删除了某些内容.当我说删除时,我的意思是删除.这些东西绝对是无法挽回的.如果您使用Time Machine或Carbon Copy Cloner或类似工具,则可能在其他地方有备份,但这与git无关.您告诉git删除内容,并遵守了.

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 when I say gives me the following error: Git: fatal: You are on a branch yet to be born.

this is what it looks like when I use the "git status" command in the terminal:

warning: could not open directory '.Trash/': Operation not permitted
On branch master

No commits yet

Untracked files:
  (use "git add <file>..."
    to include in what will be committed)
  .. / .npm /
  .. / .viminfo
  .. / .vscode /
  .. / .zsh_history
  .. / Applications /
  . /
  .. / Documents /
  .. / Downloads /
  .. / Library /
  .. / Movies /
  .. / Music /
  .. / Pictures /
  .. / Public /

  nothing added to commit but untracked files present(use "git add"
    to track)

Please don't think I came here looking for a solution. I tried pretty hard. I even read the articles here carefully.How to remove local (untracked) files from the current Git working tree.

git clean, git reset commands, such as I tried but failed. I'm trying to find out what I'm missing. I don't want to use the wrong command and ruin everything. If you can explain while you're helping, I'll know and I'll be happy. Thank you.

解决方案

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.

这篇关于如何删除所有意外添加到git系统的本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆