git add 后存储库中缺少文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24423067/
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
missing folder in repository after git add
提问by ransh
I'm using folder containing Software Development Kit (SDK), and tried to back it up with git into another folder in my laptop which I use as a git remote.
I used git add *
.
It seemed that all worked well, I received no error or warning. So then i cloned the remote into another folder, and tried to compile, but got an error saying that files are missing. It turned out that a folder is missing in git.
我正在使用包含软件开发工具包 (SDK) 的文件夹,并尝试使用 git 将其备份到我用作 git 遥控器的笔记本电脑中的另一个文件夹中。我用过git add *
。似乎一切正常,我没有收到错误或警告。然后我将遥控器克隆到另一个文件夹中,并尝试编译,但收到错误消息,提示文件丢失。原来是git中缺少一个文件夹。
Any idea what I did wrong ?
知道我做错了什么吗?
cd /home/ubuntu/backup
mkdir yamit
cd yamit
git init
git add *
git commit -m "first backup"
git remote add yamit /home/ubuntu/backup/yamit.git
git push -u yamit master
采纳答案by ransh
Ok. I've resolved this. Just needed to call add with force into repository.
好的。我已经解决了这个问题。只需要强制调用 add 到存储库中。
git add * -f
Yet, I still don't unedrstand why Git decided to ignore the folder when trying without forcing ( it's non empty folder).
然而,我仍然不明白为什么 Git 在不强制的情况下尝试时决定忽略该文件夹(它不是空文件夹)。
Thanks. Ran
谢谢。冉
回答by VonC
Whenever you have a missing resource after a git add, you can easily check if it is part of any .gitignore
with a git check-ignore
(git 1.8.4+):
每当您在 git add 之后缺少资源时,您都可以轻松检查它是否属于任何.gitignore
带有git check-ignore
(git 1.8.4+) 的资源:
git check-ignore -v path/to/missing/ressource
Simply modify the .gitignore
by removing its line ignore the resource you need.
只需.gitignore
通过删除其行来修改忽略您需要的资源。
Then add and commit again.
然后再次添加并提交。
If you don't want to modify the .gitignore
file, then a
如果你不想修改.gitignore
文件,那么
git add -f .
# or
git add -f path/to/missing/*
That can force those ignored resources to be added to the index anyway.
无论如何,这可能会强制将那些被忽略的资源添加到索引中。
回答by jlmurph
Late to the party, but i ran into this same issue.. Turns out i'd created my current project, and pushed it to a repo after working on it for a few days. Somewhere around that time i must have forgotten to add the missing directory's file to the local directory which is pushed on to my GitHub profile. Manually adding the file to the directory fixed it for me which is what led me to this conclusion.
聚会迟到了,但我遇到了同样的问题..结果我创建了我当前的项目,并在工作了几天后将它推送到了一个仓库。那个时候的某个地方,我一定忘记了将丢失目录的文件添加到本地目录中,该目录已推送到我的 GitHub 个人资料中。手动将文件添加到目录为我修复了它,这就是让我得出这个结论的原因。
Might be another thing to look at that wasn't mentioned earlier!
可能是之前没有提到的另一件事!
(mind you I use Intellij, which manages the git system in the background, the CLI approach might not have this same issue).
(请注意,我使用 Intellij,它在后台管理 git 系统,CLI 方法可能没有同样的问题)。