为什么"git status"显示太多未跟踪的文件? [英] Why does "git status" show way too much untracked files?

查看:863
本文介绍了为什么"git status"显示太多未跟踪的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

答案在底部.

我正在尝试查看git_test2目录中文件的status,该目录包含3个名为test1.txttest2.txttest3.txt的文件.

I am trying to see the status of my files in the git_test2 directory which contains 3 files named test1.txt, test2.txt and test3.txt.

这是我在Terminal中键入的内容:

This is what I typed into Terminal:

cd Desktop
cd git_test2
git status

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

Everything is good until the git status command. It should show me just 3 untracked files but instead I get this text from the Terminal:

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/

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

and after the last line there are many lines just like the last one (in red color)

我刚刚发现原因: 我需要做的只是git init,现在它可以准确显示我的期望了.谢谢大家!

I just found out the reason: All I needed to do is git init, now it shows exactly what I expected. Thank you everyone!

推荐答案

为什么文件太多?

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

Why are there so many files?

A git repository is just a .git/ directory (folder) located in your project's directory. Like this: myproject/.git/.

如果当前目录中没有git存储库,则git 在父目录中搜索,然后在父目录的父目录中搜索.

If there's no git repository in your current directory, git searches in the parent directory, then in parent's parent and up to top.

由于您的路径为/Users/ishayfrenkel1/Desktop/git_test2,因此该路径中的某处应该有一个git repo.

As your path was /Users/ishayfrenkel1/Desktop/git_test2, there should be a git repo somewhere in this path.

new file:   ../../Library/Preferences/AndroidStudio1.2/options/git.xml

新文件的路径比/Library(为/Library/Users/ishayfrenkel1/Library)至少高两个级别.这意味着您已经启动了一个git存储库:

New files have path at least two levels up from /Library (which is either /Library or /Users/ishayfrenkel1/Library). It means that you have a git repository initiated:

  • 在您的主目录中:~/,在OSX上为/Users/<username>/或在Linux上为/home/<username>.
  • 或在所有目录的父目录的根目录/中.
  • either in your home directory: ~/, /Users/<username>/ on OSX or /home/<username> on Linux.
  • or in the root directory, /, the parent of all directories.

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

Most probably you opened the Terminal and typed git init. Terminal opens in your home directory by default and that's where the new repository was created.

搜索并删除它.以下命令之一应正常运行.在那里!

Search for it and delete it. One of the following commands should run without an error. And there it is!

ls /.git
ls ~/.git

现在通过以下方式删除存储库

Now remove the repository with

rm -rf ~/.git

这篇关于为什么"git status"显示太多未跟踪的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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