Git - 不会添加文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7490798/
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
Git - Won't add files?
提问by Martin Blore
I'm having issues where I can't add files to my repository.
我遇到了无法将文件添加到我的存储库的问题。
I'm using GIT on windows, in Aptana Studio for some Ruby development.
我在 Windows 上使用 GIT,在 Aptana Studio 中进行一些 Ruby 开发。
I've managed to push a few files up to GitHub, but then after this, everything's stopped working. I have for example a new sub-folder in my master directory, with 2 ruby files inside. If I call "git add .", and then "git status" and it keeps saying "working directory clean" and has nothing to commit.
我已经设法将一些文件推送到 GitHub,但是在此之后,一切都停止了。例如,我的主目录中有一个新的子文件夹,里面有 2 个 ruby 文件。如果我调用“git add .”,然后调用“git status”,它会一直说“工作目录干净”并且没有任何可提交的内容。
I've tried "git add folder/myfile.rb" and still nothing.
我试过“git add folder/myfile.rb”,但仍然没有。
Anyone any idea's what I can try?
有人知道我可以尝试什么吗?
回答by zrisher
I found myself in a similar situation as the poster:
我发现自己处于与海报相似的情况:
If I call "git add .", and then "git status" and it keeps saying "working directory clean" and has nothing to commit.
如果我调用“git add .”,然后调用“git status”,它会一直说“工作目录干净”并且没有任何可提交的内容。
But I had a different solution than what's here. Since I came to this first, I hope to save others some time.
但我有一个与这里不同的解决方案。由于我是第一次来到这里,我希望能节省一些时间。
From the above answers and what I've seen elsewhere, the usual fixes to this problem are:
从上面的答案和我在其他地方看到的,这个问题的通常解决方法是:
- Ensure there are actually saved changes on the file in question
- Ensure the file doesn't meet your exclude rules in
.gitignore
and.git/info/exclude
- Ensure you're not trying to add an empty folder. Git won't track those. Standard solution is to place a blank file named
.gitkeep
as a placeholder so git will track the folder.
- 确保有问题的文件上实际保存了更改
- 确保文件不符合您的排除规则
.gitignore
和.git/info/exclude
- 确保您没有尝试添加空文件夹。Git 不会跟踪这些。标准解决方案是放置一个名为
.gitkeep
占位符的空白文件,以便 git 跟踪该文件夹。
In my case, I had originally tried to create a git repo around an existing repo (not knowing it was there). I had removed the .git
folder from this sub repo a while ago, but I didn't realize that it was too late, and git was already tracking it as a submodule. You can read more about how these behave and how to remove them here, but
就我而言,我最初尝试围绕现有存储库创建一个 git 存储库(不知道它在那里)。.git
不久前我从这个子仓库中删除了文件夹,但我没有意识到为时已晚,并且 git 已经将其作为submodule 进行跟踪。您可以在此处阅读有关这些行为以及如何删除它们的更多信息,但是
- the solution for me was to simply run
git rm --cached path_to_submodule
.
- 我的解决方案是简单地运行
git rm --cached path_to_submodule
.
回答by antfx
To add to the possible solutions for other users:
为其他用户添加可能的解决方案:
Make sure you have not changed the case of the folder name in Windows:
确保您没有更改 Windows 中文件夹名称的大小写:
I had a similar problem where a folder called Setup
controlled by Git and hosted on GitHub, all development was done on a Windows machine.
我有一个类似的问题,一个Setup
由 Git 控制并托管在 GitHub 上的文件夹,所有开发都是在 Windows 机器上完成的。
At some point I changed the folder to setup
(lower case S). From that point on when I added new files to the setup folder they were stored in the setup
folder and not the Setup
folder, but I guess because I was developing on a Windows machine the existing Setup
folder in git/github was not changed to setup
.
在某些时候,我将文件夹更改为setup
(小写 S)。从那时起,当我将新文件添加到 setup 文件夹时,它们存储在setup
文件夹中而不是Setup
文件夹中,但我猜是因为我在 Windows 机器上开发Setup
,git/github 中的现有文件夹没有更改为setup
.
The result was that I couldn't see all of the files in the setup
in GitHub. I suspect that if I cloned the project on a *nix machine I would have seen two folders, Setup
and setup
.
结果是我setup
在 GitHub中看不到所有文件。我怀疑如果我在 *nix 机器上克隆该项目,我会看到两个文件夹,Setup
以及setup
.
So make sure you have not changed the case of the containing folder on a Windows machine, if you have then I'd suggest:
因此,请确保您没有更改 Windows 机器上包含文件夹的大小写,如果您有那么我建议:
- Renaming the folder to something like
setup-temp
git add -A
git commit -m "Whatever"
- Rename the folder back to what you want
git add -A
git commit -m "Whatever"
- 将文件夹重命名为类似
setup-temp
git add -A
git commit -m "Whatever"
- 将文件夹重命名回您想要的名称
git add -A
git commit -m "Whatever"
回答by mobiusloopy
If the file is excluded by .gitignore
and you want to add it anyway, you can force it with:
如果文件被排除在外.gitignore
并且您仍然想添加它,您可以使用以下命令强制它:
git add -f path/to/file.ext
回答by Brad
Odd, but I fought with git all night to add a file. Turns out it was already added. Git wasn't picking up my changes, as the changes weren't being saved, as the file was inaccessible by my account, and my IDE wasn't reporting this over SSH.
奇怪,但我整晚都在用 git 添加一个文件。原来它已经添加了。Git 没有接收我的更改,因为更改没有被保存,因为我的帐户无法访问该文件,并且我的 IDE 没有通过 SSH 报告这一点。
In short, check to make sure you don't have it already added to the repository.
简而言之,检查以确保您尚未将其添加到存储库中。
回答by sparrow
Double check your .gitignore
file to make sure that the file is able to be seen by Git. Likewise, there is a file .git/info/exclude
that 'excludes' files/directories from the project, just like a .gitignore
file would.
仔细检查您的.gitignore
文件以确保该文件能够被 Git 看到。同样,有一个文件.git/info/exclude
从项目中“排除”文件/目录,就像.gitignore
文件一样。
回答by Chris G.
Best bet is to copy your folder. Delete the original. Clone the project from github, copy your new files into the new cloned folder, and then try again.
最好的办法是复制您的文件夹。删除原来的。从 github 克隆项目,将新文件复制到新的克隆文件夹中,然后重试。
回答by gaoagong
I just had this issue and the problem was that I was inside a directory and not at the top level. Once I moved to the top level it worked.
我刚刚遇到了这个问题,问题是我在一个目录中而不是在顶层。一旦我移到顶层,它就起作用了。
回答by codelearner336
I had this problem with the first program in the folder. I did "git add" then "git commit". "git status" gave the error described i.e. "nothing to commit, working directory clean"
我在文件夹中的第一个程序中遇到了这个问题。我做了“git add”然后“git commit”。“git status”给出了描述的错误,即“没有提交,工作目录干净”
I ended up deleting the .git file from the program folder. Then I did a new git init, git add and git commit and it worked.
我最终从程序文件夹中删除了 .git 文件。然后我做了一个新的 git init、git add 和 git commit 并且它起作用了。
回答by Max_Power89
回答by Andrejs Cainikovs
How about the standard procedure:
标准程序如何:
git add folder
git commit
This will add the folder and all it's files with a single command.
Please note, git is not able to store empty folders.
这将使用单个命令添加文件夹及其所有文件。
请注意,git 无法存储空文件夹。
If commit didn't worked, the first place you should check is probably .gitignore
.
如果提交不起作用,您应该检查的第一个地方可能是.gitignore
.