为什么 Git 不跟踪子目录中的更改?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9034999/
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-10 12:50:45  来源:igfitidea点击:

Why isn't Git tracking changes in a subdirectory?

gitgithub

提问by Giedrius

I've created git repository, added code and pushed it to GitHub.

我已经创建了 git 存储库,添加了代码并将其推送到 GitHub。

Then locally, I've edited the file Eila.Analyser/Program.cs, that was added to GitHub in first commit, saved it and git statussays there's no changes.

然后在本地,我编辑了Eila.Analyser/Program.cs第一次提交时添加到 GitHub的文件,保存并git status说没有任何更改。

Ok, I think, must have messed something up, git reset --hard HEAD, and as I understand that should revert everything, but my file is not reverted.

好吧,我想,一定是搞砸了,git reset --hard HEAD据我所知,这应该恢复一切,但我的文件没有恢复。

So I think I'm doing something wrong. I edit file in root folder, git status- shows there are changes, works as suspected, so it works on files in root folder, but not in sub folders.

所以我觉得我做错了什么。我在根文件夹中编辑文件,git status- 显示有更改,正常工作,因此它适用于根文件夹中的文件,但不适用于子文件夹中。

Am I missing something obvious here?

我在这里遗漏了一些明显的东西吗?

UPDATE: Evidence, that file I'm editing was really commited (git log --stat):

更新:证据,我正在编辑的文件确实已提交 ( git log --stat):

enter image description here

在此处输入图片说明

if it helps, tree picture:

如果有帮助,树图片:

enter image description here

在此处输入图片说明

UPDATE2: Ok, I thought I really messed something up, so I've deleted folder, where was my solution, cloned once again from gitHub, and my local code still differs from existing in gitHub and git status sees no changes, git log origin/master..HEADgives nothing.

UPDATE2:好的,我以为我真的搞砸了,所以我删除了文件夹,我的解决方案在哪里,从 gitHub 再次克隆,我的本地代码仍然与 gitHub 中的现有代码不同,并且 git status 没有看到任何变化,git log origin/master..HEAD什么也没给出。

采纳答案by Giedrius

So finally it worked. I've removed changed files in local folder - then suddenly git statusstarted to see, that those files are missing. So I've restored them and git statusstarted to see, that files are modified.

所以最后它奏效了。我已经删除了本地文件夹中已更改的文件 - 然后突然git status开始看到,这些文件丢失了。所以我恢复了它们并git status开始看到文件被修改了。

回答by Koraktor

Try running git update-index --really-refresh.

尝试运行git update-index --really-refresh

I did have similar problems on Windows and that solves it.

我在 Windows 上确实遇到过类似的问题,这解决了它。

You should also check the core.ignoreStatoption with git config.

您还应该使用 来检查core.ignoreStat选项git config

回答by Timothy Quang Phuc Nguyen

Sometimes I have the same problem, especially when I have subfolder which is another git repo itself. The solution is: renaming the folders. Try switching the folder name to something else. Commit that, then rename it back. If the subfolder itself is another Git repo, and you want it to be totally detached from the mainstream, and follow your repo, you should remove the remote of that subfolder first.

有时我会遇到同样的问题,尤其是当我有另一个 git repo 本身的子文件夹时。解决方法是:重命名文件夹。尝试将文件夹名称切换为其他名称。提交它,然后将其重命名。如果子文件夹本身是另一个 Git 存储库,并且您希望它与主流完全分离,并跟随您的存储库,您应该首先删除该子文件夹的远程。

回答by sqp_125

For me the solution was

对我来说,解决方案是

Renaming the untracked folder

重命名未跟踪的文件夹

回答by Ashwin

For me, the problem was that I had a filename in my .gitignore file which did not exist. Removing this invalid filename from .gitignore solved the problem. Also, I deleted all the .gitignore files from subdirectories and only kept the top-level .gitignore file.

对我来说,问题是我的 .gitignore 文件中有一个不存在的文件名。从 .gitignore 中删除这个无效的文件名解决了这个问题。另外,我从子目录中删除了所有 .gitignore 文件,只保留了顶级 .gitignore 文件。

回答by Tony Barganski

PROBELM (In my case)
Performing a git checkout -b <branch_name>had no effect and my folder and files in that branch were still not visible locally, though they are on our gitlab server.

问题(就我而言)
执行 agit checkout -b <branch_name>没有效果,我在该分支中的文件夹和文件在本地仍然不可见,尽管它们在我们的 gitlab 服务器上。

SOLUTION
Copied the SHA hash of last commit in that branch, then locally:

解决方案
复制该分支中最后一次提交的 SHA 哈希,然后在本地复制:

git checkout -b <branch_name> #SHA Hash

git checkout -b <branch_name> #SHA Hash

Now I see the expected sub-directories and files.

现在我看到了预期的子目录和文件。