简体   繁体   English

Git:无法添加目录

[英]Git: unable to add a directory

I want to add a new directory to a project, but I am not able to do that. 我想向项目添加一个新目录,但是我无法做到这一点。

If I do git status the new directory does not show. 如果执行git status ,则不会显示新目录。

If do git add -A nothing happens, when I do git status the directly does not show. 如果执行git add -A什么也没有发生,当我执行git status ,不会直接显示。

There is not gitignore (that I can find at least...) 没有gitignore (我至少可以找到...)

There is an exclude file that contains: 有一个exclude文件,其中包含:

Foo.Mobile\platforms\android\assets
Foo.Mobile/platforms/android/.idea/workspace.xml

But I don't think that is the problem. 但是我不认为这是问题所在。 The directory I have created is inside: 我创建的目录在里面:

C:\\Users\\Bar\\git\\FooAndroid\\Foo.Mobile\\platforms

And there is a sparse-checkout file that contains 还有一个sparse-checkout文件,其中包含

Foo.Mobile/platforms/android/*

And again I don't think that is the problem. 再一次,我认为这不是问题。

The project is IntelliJ based. 该项目基于IntelliJ。

Thanks 谢谢

Git does not provide for working with empty directories or files. Git不提供处理空目录或文件的功能。 Try creating a dummy file in the directory. 尝试在目录中创建一个虚拟文件。

The reason for this is that Git works only on changes in files and if there is no text it can not compare anything. 这是因为Git仅适用于文件更改,并且如果没有文本,它就无法进行任何比较。

A diff file also contains the location (directory) to the file and thus automatically adds the directory. 差异文件还包含文件的位置(目录),因此会自动添加目录。

Here is a solution if you really want to keep an empty directory in Git. 如果您确实要在Git中保留一个空目录, 是一个解决方案。

First, you must ensure that there is a file in the directory you're adding, since git only operates on files. 首先,必须确保要添加的目录中有一个文件,因为git仅对文件起作用。 Since you've already done this, the next thing to do is to trouble-shoot. 由于您已经完成了此操作,因此下一步是进行故障排除。

Using git add . 使用git add . will only add from the current directory downward; 只会从当前目录向下添加; if used, it must be from the root of the repository. 如果使用,则必须从存储库的根目录开始。 Sometimes, git add --all will be easier and more appropriate. 有时, git add --all会更容易并且更合适。

You need to look for a .gitignore file. 您需要寻找一个.gitignore文件。 Notice there is a "dot" at the beginning of the file; 注意文件的开头有一个“点”。 on most operating systems (and certainly Windows), these files are classified as "system" files and are hidden by default; 在大多数操作系统(当然还有Windows)上,这些文件被归类为“系统”文件,默认情况下处于隐藏状态; you can, however, make them visible in an operating-system-dependent manner. 但是,您可以使它们以依赖于操作系统的方式可见。 The .gitignore should be at the root level of the repository you cloned, but sometimes there may be more than one in different directories. .gitignore应该位于您克隆的存储库的根目录下,但是有时在不同的目录中可能有多个。 Using a command-line or GUI tool may help find any .gitignore files that may exist. 使用命令行或GUI工具可能有助于查找可能存在的任何.gitignore文件。

If you're looking at a .gitignore file, be sure that you understand any regular expressions which may be inadvertently matching the file you're trying to add. 如果您正在查看.gitignore文件,请确保您了解任何正则表达式,它们可能无意中与您要添加的文件匹配。 You could, as a simple test, try renaming the .gitignore and trying the add again, but be ready to unstage the files that will be added as a result. 作为一个简单的测试,您可以尝试重命名.gitignore并再次尝试添加,但可以准备取消转储将作为结果添加的文件。 You could also try git check-ignore -v <dirname> , or read the help for check-ignore for more advanced options. 您也可以尝试git check-ignore -v <dirname> ,或者阅读帮助中的check-ignore以获得更多高级选项。 Some useful help on this is offered by git help gitignore . git help gitignore提供了一些有用的帮助。

If all else fails, try adding an arbitrary test file, to ensure that something else is not wrong with the repository. 如果所有其他方法均失败,请尝试添加任意测试文件,以确保存储库没有其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM