为什么"git status"显示太多未跟踪的文件?

Ish*_*kel 7 git git-status

在底部回答.

我试图statusgit_test2目录中看到我的文件,其中包含3个名为的文件test1.txt,test2.txttest3.txt.

这是我输入终端的内容:

cd Desktop
cd git_test2
git status
Run Code Online (Sandbox Code Playgroud)

git status命令之前一切都很好.它应该只显示3个未跟踪的文件,但我从终端获取此文本:

On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

new file:   ../../AndroidStudioProjects/Sunshine/app/src/main/res/layout/list_item_forecast.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/fileEditorProviderManager.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/git.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/other.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/runner.layout.xml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

modified:   ../../AndroidStudioProjects/Sunshine/app/src/main/res/layout/list_item_forecast.xml
modified:   ../../Library/Preferences/AndroidStudio1.2/options/runner.layout.xml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

../../.CFUserTextEncoding
../../.Rsupport/
Run Code Online (Sandbox Code Playgroud)

在最后一行之后有很多行就像最后一行一样(红色)

我刚刚发现了原因:我需要做的就是git init,现在它显示了我的预期.谢谢大家!

Nic*_*kin 11

为什么有这么多文件?

git存储库只是.git/位于项目目录中的目录(文件夹).像这样:myproject/.git/.

如果当前目录中没有git存储库,git将在父目录中搜索,然后在父目录中搜索,直到顶部.

正如你的道路一样/Users/ishayfrenkel1/Desktop/git_test2,在这条道路的某个地方应该有一个git repo.

new file:   ../../Library/Preferences/AndroidStudio1.2/options/git.xml
Run Code Online (Sandbox Code Playgroud)

新文件的路径至少有两个级别/Library(或者是/Library或者/Users/ishayfrenkel1/Library).这意味着你已经启动了一个git存储库:

  • 在您的主目录中:~/,/Users/<username>/在OSX上或/home/<username>在Linux上.
  • 或者在根目录中,/所有目录的父目录.

怎么回事.

很可能你打开了终端并输入了git init.默认情况下,终端在您的主目录中打开,这是创建新存储库的位置.

现在做什么.

搜索并删除它.应该运行以下命令之一而不会出现错误.它就是!

ls /.git
ls ~/.git
Run Code Online (Sandbox Code Playgroud)

现在删除存储库

rm -rf ~/.git
Run Code Online (Sandbox Code Playgroud)