git git不添加现有文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32000525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:16:23  来源:igfitidea点击:

git not adding existing folder

git

提问by duxfox--

I started working on a project recently, then decided to push it up to github. So I did the following:

我最近开始做一个项目,然后决定把它推到 github。所以我做了以下事情:

cd <root>
git init
git add -A
git commit -m 'message'
git remote add origin <ur>
git push -u origin master

this, however, omitted an entire folder of my project. its basically a folder 1 level down from my root folder so:

然而,这省略了我项目的整个文件夹。它基本上是一个比我的根文件夹低 1 级的文件夹,因此:

root
 -folder //omitted

I'm trying to do git add -A / git add * / git add .but every time I do git statusit says there are changes but the folder is untracked.

我正在尝试这样做,git add -A / git add * / git add .但每次我这样做git status时都说有更改,但文件夹未跟踪。

I even tried to specifically add the folder git add folderNamebut git statusis still showing it as untracked.

我什至尝试专门添加该文件夹,git add folderNamegit status仍将其显示为未跟踪。

I also tried to navigate into the folder itself, and do a git add *and that added everything INSIDE of this folder, but I just cant seem to add the folder itself.

我还尝试导航到文件夹本身,然后执行git add *并添加了该文件夹内的所有内容,但我似乎无法添加文件夹本身。

any idea what else I can do?

知道我还能做什么吗?

回答by wisbucky

A subfolder will not be added with git add .(or similar commands) if it contains a .gitdir because it will be assumed to be a git submodule.

如果子文件夹git add .包含.git目录,则不会使用(或类似命令)添加子文件夹,因为它将被假定为 git 子模块。

You can rm -rf .gitin the subfolder if it's not supposed to be a submodule.

rm -rf .git如果它不应该是子模块,则可以在子文件夹中。

回答by mipadi

Are there files in the folder? Git doesn't track folders, only files; you can't add an empty folder to a Git repo. However, you can put an empty file in that folder (.gitignoreor .blankare common file names) and add those files to the folder.

文件夹中有文件吗?Git 不跟踪文件夹,只跟踪文件;您不能向 Git 存储库添加空文件夹。但是,您可以在该文件夹中放置一个空文件(.gitignore.blank常见文件名)并将这些文件添加到该文件夹​​中。