无法强制添加 Git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1128828/
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
Unable to Git-add with force
提问by Léo Léopold Hertz ??
I get git-status at ~/bin:
我在 ~/bin 得到 git-status:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# screen/dev/
I run
我跑
git add --force screen/dev/
I get the same git-status as before. I add each file in the folder independently, but I get the same git-status.
我得到与以前相同的 git-status。我独立地在文件夹中添加每个文件,但我得到相同的 git-status。
There is no .git in screen/dev/. The folder seems not to be a sumbodule.
screen/dev/ 中没有 .git。该文件夹似乎不是一个sumbodule。
How can you add a folder and its content with force to my git at ~/bin?
如何将文件夹及其内容强行添加到 ~/bin 中的 git 中?
采纳答案by Léo Léopold Hertz ??
The problem can be solved by renaming the folder and adding the folder with a new name to Git.
可以通过重命名文件夹并将具有新名称的文件夹添加到 Git 来解决该问题。
This suggests me that there must be some file manipulating the folder name dev
.
这表明我必须有一些文件操作文件夹名称dev
。
回答by VonC
You should not need '--force
' or '-f
' option: see git add:
您不应该需要 ' --force
' 或 ' -f
' 选项:请参阅git add:
-f
--force
:
-f
--force
:
Allow adding otherwise ignoredfiles.
允许添加否则被忽略的文件。
In your case, you may not want to add all files, included ignored files under screen/dev directory.
在您的情况下,您可能不想添加所有文件,包括 screen/dev 目录下被忽略的文件。
git add screen/dev
should be enough (without options or ending '/')
应该足够了(没有选项或结尾'/')
回答by Tyrone Slothrop
Is that a typo on cut paste?
这是切糊上的错字吗?
If not, it should be
如果不是,应该是
git add --force screen/dev
回答by Fake Code Monkey Rashid
Try doing:
尝试做:
git add -A .
Also, if you have a .gitignore file it's also possible that you are unintentionally ignoring something (ie: possibly the files you are trying to add).
此外,如果您有一个 .gitignore 文件,您也可能无意中忽略了某些内容(即:可能是您尝试添加的文件)。
回答by solidak
If nothing works...
如果没有任何效果...
- Move the stubborn directory to a temp location outside the repo
- Remove any remaining traces of the stubborn directory in the repo
- Push and make sure that local is synced with remote
- Move the stubborn directory from the temp location back to the repo (You don't have to rename)
git add -A
- Commit and push
- 将顽固目录移动到 repo 之外的临时位置
- 删除 repo 中顽固目录的任何剩余痕迹
- 推送并确保本地与远程同步
- 将顽固目录从临时位置移回 repo(您不必重命名)
git add -A
- 提交和推送
回答by Deiu
I've also found that you have to have at least a file in that dir in order to be picked up by git. git add screen/dev
won't work if there are no files inside.
我还发现您必须在该目录中至少有一个文件才能被 git 接收。git add screen/dev
如果里面没有文件,将无法工作。