无法将子文件夹添加到 Github 中的远程存储库
Not able to add a subfolder to remote repository in Github
在我的电脑里有一个文件夹nextdoor
,里面还有一个子文件夹source
。我所有的图像和代码都在 source
文件夹中,但不知何故我无法将这个特定的子文件夹推送到远程存储库。
远程存储库:LINK
如果你去远程仓库,你可以看到 source
文件夹没有被添加。子文件夹也不为空。我尝试了很多方法,但不幸的是,我无法将这个特定的子文件夹向上推。
如果我这样做 git status
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
子文件夹总数:
bin include lib local pip-selfcheck.json README.md source static_cdn
既然我可以推送所有文件夹,但为什么source
不上?
在 source
文件夹内:
crytography manage.py registration.txt templates
db.sqlite3 nextdoor static
.gitignore 文件:
# global gitignore for IDE, etc
# -- should still exclude project specific ignores in .gitignore
# system junk
.netrwhist
.Trash-1000
*.pyc
npm-debug.log
# IDEs
.idea
.env
# private files
id_rsa
*.key
有人能帮帮我吗?
您的最后一次提交 (815bb7d) 已损坏。它添加了 "half a submodule".
当使用 git submodule add
添加子模块时会发生两件事:创建一个文件 .gitmodules
,其中包含子模块的 URL,并创建一个 "folder",注释随着你的子模块的提交。
在你的情况下,你设法创建了一个包含第二个但不是第一个的提交:
$ git ls-tree 815bb7d28719ab66e765ba8e265eb317766b68db
100644 blob 506c8957ac440449d375416f45c6753a3cb65d83 .gitignore
100644 blob 5f8188352aa817edb6808536f598d3ac74d448d7 README.md
040000 tree c336cc94ab9a686360ee9e6f330558cdee571e9d bin
040000 tree 334b6ff5f7c516042b7a185ec6106208df8495a7 include
040000 tree e65f051d2d0e9f2648a6b83f0ef0836893423ee5 lib
040000 tree 63a79abf5f366fc25b0b47fc527ea237163a0505 local
100644 blob 2dbf660a900d007e70510ff0ccc2c553b32d6120 pip-selfcheck.json
160000 commit 4732e130e321cacd355f8bffbf1c1726e94576c6 source
040000 tree 12edc4bcf6f3ab7a76dc5bda57a940c0caeae7e0 static_cdn
你看,提交对象被存储但是相应的.gitmodules
文件没有。
您至少有两个选择,要么丢弃损坏的提交 (git reset --hard 815bb7d28719ab66e765ba8e265eb317766b68db^
),要么按照评论中的建议删除 .git
目录,从而完全丢弃整个历史记录。
请注意,不可能 推送目录。您始终在本地存储库中进行本地提交,然后通过推送本地提交将本地存储库与远程存储库同步。
在您的情况下,您无法将 "source" 中的文件添加到您的存储库,因为 "source" 被视为一个单独的存储库,一个子模块。
这是最快的解决方案,但肯定不是最好的解决方案。您的 git 存储库中似乎有问题。我让它工作的最快方法是销毁你的 git 存储库并重新开始。 警告您将丢失您的历史记录:
rm -rf .git
git init
git add ...
我最好调查一下为什么 git 存储库坏了;正如@michas
所建议的
在我的电脑里有一个文件夹nextdoor
,里面还有一个子文件夹source
。我所有的图像和代码都在 source
文件夹中,但不知何故我无法将这个特定的子文件夹推送到远程存储库。
远程存储库:LINK
如果你去远程仓库,你可以看到 source
文件夹没有被添加。子文件夹也不为空。我尝试了很多方法,但不幸的是,我无法将这个特定的子文件夹向上推。
如果我这样做 git status
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
子文件夹总数:
bin include lib local pip-selfcheck.json README.md source static_cdn
既然我可以推送所有文件夹,但为什么source
不上?
在 source
文件夹内:
crytography manage.py registration.txt templates
db.sqlite3 nextdoor static
.gitignore 文件:
# global gitignore for IDE, etc
# -- should still exclude project specific ignores in .gitignore
# system junk
.netrwhist
.Trash-1000
*.pyc
npm-debug.log
# IDEs
.idea
.env
# private files
id_rsa
*.key
有人能帮帮我吗?
您的最后一次提交 (815bb7d) 已损坏。它添加了 "half a submodule".
当使用 git submodule add
添加子模块时会发生两件事:创建一个文件 .gitmodules
,其中包含子模块的 URL,并创建一个 "folder",注释随着你的子模块的提交。
在你的情况下,你设法创建了一个包含第二个但不是第一个的提交:
$ git ls-tree 815bb7d28719ab66e765ba8e265eb317766b68db
100644 blob 506c8957ac440449d375416f45c6753a3cb65d83 .gitignore
100644 blob 5f8188352aa817edb6808536f598d3ac74d448d7 README.md
040000 tree c336cc94ab9a686360ee9e6f330558cdee571e9d bin
040000 tree 334b6ff5f7c516042b7a185ec6106208df8495a7 include
040000 tree e65f051d2d0e9f2648a6b83f0ef0836893423ee5 lib
040000 tree 63a79abf5f366fc25b0b47fc527ea237163a0505 local
100644 blob 2dbf660a900d007e70510ff0ccc2c553b32d6120 pip-selfcheck.json
160000 commit 4732e130e321cacd355f8bffbf1c1726e94576c6 source
040000 tree 12edc4bcf6f3ab7a76dc5bda57a940c0caeae7e0 static_cdn
你看,提交对象被存储但是相应的.gitmodules
文件没有。
您至少有两个选择,要么丢弃损坏的提交 (git reset --hard 815bb7d28719ab66e765ba8e265eb317766b68db^
),要么按照评论中的建议删除 .git
目录,从而完全丢弃整个历史记录。
请注意,不可能 推送目录。您始终在本地存储库中进行本地提交,然后通过推送本地提交将本地存储库与远程存储库同步。
在您的情况下,您无法将 "source" 中的文件添加到您的存储库,因为 "source" 被视为一个单独的存储库,一个子模块。
这是最快的解决方案,但肯定不是最好的解决方案。您的 git 存储库中似乎有问题。我让它工作的最快方法是销毁你的 git 存储库并重新开始。 警告您将丢失您的历史记录:
rm -rf .git
git init
git add ...
我最好调查一下为什么 git 存储库坏了;正如@michas
所建议的