看不到添加到我的 git 工作目录中的新文件

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

Cannot see new files added to my git working directory

git

提问by ant2009

git version 1.7.4.1

git 版本 1.7.4.1

I am using git on Ubuntu.

我在 Ubuntu 上使用 git。

I have copied some files from another directory to my git working directory. Normally would appear under Untracked files. However, they do not appear. So I cannot add them.

我已将一些文件从另一个目录复制到我的 git 工作目录。通常会出现在Untracked files. 但是,它们不会出现。所以我不能添加它们。

When I do a git statusthe new files are not shown.

当我做一个git status新文件时没有显示。

I tried to add them by doing git add source.cthen tried git status. The file was not show.

我尝试通过执行git add source.cthen 尝试添加它们git status。该文件未显示。

So I opened the file and did a save asas the same name. git status still failed to see the file.

所以我打开了文件并做了save as一个同名。git status 仍然无法看到该文件。

I have done a git ls-filesand the new files are shown ok.

我做了一个git ls-files,新文件显示正常。

I have checked the file permissions and they are the same as all the current files in my git directory.

我检查了文件权限,它们与我的 git 目录中的所有当前文件相同。

I have never had this problem before.

我以前从未遇到过这个问题。

Many thanks for any suggestions,

非常感谢您的任何建议,

回答by Richard Hansen

If git ls-filesshows source.c, then it must already be in the index. This means that it is already tracked, and possibly already committed. If source.cisn't showing up in git statusat all, then the file must have been committed.

如果git ls-files显示source.c,则它必须已经在索引中。这意味着它已经被跟踪,并且可能已经提交。如果source.c根本没有出现git status,则该文件必须已提交。

Try modifying the file to see if it shows up as modified in git status. To really convince yourself that the file is checked in, run git cat-file -p HEAD:source.cto see the contents of the checked-in file (see git help revisionsfor documentation about the HEAD:source.csyntax).

尝试修改文件以查看它是否显示为已修改git status。要真正说服自己文件已签入,请运行git cat-file -p HEAD:source.c以查看签入文件的内容(git help revisions有关HEAD:source.c语法的文档,请参阅参考资料)。

In addition, one or more of the following may be true:

此外,以下一项或多项可能为真:

  • The file has been modified, but the 'assume unchanged' bit is set in the index. Take a look at the output of git ls-files -v source.c. If the first column is a lower-case letter, then the 'assume unchanged' bit is set. This will prevent any changes from showing up in git status. You can turn off the 'assume unchanged' bit by running git update-index --no-assume-unchanged source.c.
  • The file has been modified, but the 'skip-worktree' bit is set in the index. If the first column of the output of git ls-files -v source.cis sor Sthen the 'skip-worktree' bit is set. You can turn off the 'skip-worktree' bit by running git update-index --no-skip-worktree source.c.
  • Your index is corrupt. Try deleting .git/index(Git will recreate it as necessary).
  • Filesystem issues are preventing stat()from working properly. Try running git update-index --really-refresh. If your working directory is on a network drive (NFS, sshfs, etc.) try moving your repository to a local drive.
  • 该文件已被修改,但在索引中设置了“假设未更改”位。看看输出git ls-files -v source.c。如果第一列是小写字母,则设置“假设不变”位。这将防止任何更改出现在git status. 您可以通过运行关闭“假设不变”位git update-index --no-assume-unchanged source.c
  • 该文件已被修改,但在索引中设置了“skip-worktree”位。如果输出的第一列git ls-files -v source.csS则设置“skip-worktree”位。您可以通过运行关闭“跳过工作树”位git update-index --no-skip-worktree source.c
  • 您的索引已损坏。尝试删除.git/index(Git 会根据需要重新创建)。
  • 文件系统问题导致stat()无法正常工作。尝试运行git update-index --really-refresh。如果您的工作目录位于网络驱动器(NFS、sshfs 等)上,请尝试将存储库移动到本地驱动器。

回答by hammar

It's hard to tell what's wrong from the information given, however as a workaround you can try git add -f filename.c. This will add the file even if it would otherwise be ignored.

很难从给出的信息中判断出什么问题,但是作为一种解决方法,您可以尝试git add -f filename.c. 即使文件会被忽略,这也会添加文件。

回答by Jani Hartikainen

This is really a poke in the dark, but I've occasionally had similar issues and it has been a case of one of these:

这真的是在黑暗中戳戳,但我偶尔会遇到类似的问题,这是其中一个的案例:

  • You have a rule in .gitignore which ignores the files
  • You have a .git dir in one of the directories you've copied
  • 您在 .gitignore 中有一个规则,它忽略文件
  • 您在复制的目录之一中有一个 .git 目录

回答by Vinay Vemula

I was create a package ending with image.gen which had a corresponding directory ending with image/gen. And there was a .gitignore entry, that was specific to Android gen/.

我创建了一个以 image.gen 结尾的包,它有一个以 image/gen 结尾的相应目录。还有一个 .gitignore 条目,它特定于 Android gen/。

This was leading to file not getting added to git/ showing in git status.

这导致文件未添加到 git/ 显示在 git status 中。

Check below, it helped me solve the issue.

检查下面,它帮助我解决了问题。



Use git check-ignorecommand to debug your gitignore file (exclude files).

使用git check-ignore命令来调试你的 gitignore 文件(排除文件)。

In example:

例如:

$ git check-ignore -v config.php
.gitignore:2:src    config.php

The above output details about the matching pattern (if any) for each given pathname (including line).

以上输出有关每个给定路径名(包括行)的匹配模式(如果有)的详细信息。

So maybe your file extension is not ignored, but the whole directory.

所以也许你的文件扩展名没有被忽略,而是整个目录。

The returned format is:

返回格式为:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

Or use the following command to print your .gitignorein user and repo folder:

或者使用以下命令打印您的.gitignorein 用户和 repo 文件夹:

cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude

Alternatively use git add -fwhich allows adding otherwise ignored files.

或者使用git add -f它允许添加否则被忽略的文件。

See: man gitignore, man git-check-ignorefor more details.

请参阅:man gitignoreman git-check-ignore了解更多详情。

https://stackoverflow.com/a/28918909/4082503

https://stackoverflow.com/a/28918909/4082503

回答by Black

It is most likely ignored by your .gitignorefile.

它很可能被您的.gitignore文件忽略。

Call git status --ignoredand see if your file appears.

打电话git status --ignored看看你的文件是否出现。

回答by Diorgo

I had the same problem. Git did not show any new files added to my project.

我有同样的问题。Git 没有显示添加到我的项目中的任何新文件。

Mine was caused by the following: Somehow my project's main folder got added to the “Repository-specific ignore list” (that's what it's called in SourceTree). This is the “.gitignore” file in the root of my project's main folder.

我是由以下原因引起的:不知何故,我的项目的主文件夹被添加到“特定于存储库的忽略列表”(这就是它在 SourceTree 中的名称)。这是我项目主文件夹根目录中的“.gitignore”文件。

It worked after I deleted the folder name in the “.gitignore” file.

在我删除“.gitignore”文件中的文件夹名称后,它起作用了。

回答by Kfir Ilani

It could be that 3rd party application updated your "gitignore_global.txt" file (~/.gitignore_globalon Linux / OS X). It happned to me. I installed "Source tree" and notice after that git does not tracked new files. It found that "Source tree" changed "gitignore_global.txt" file and add it several extension to not monitor. Try to locate this file and see if there file's extensions that shuold not be there

可能是第 3 方应用程序更新了您的“ gitignore_global.txt”文件(~/.gitignore_global在 Linux/OS X 上)。它发生在我身上。我安装了“源树”,然后注意到 git 没有跟踪新文件。它发现“源树”更改了“gitignore_global.txt”文件并添加了几个扩展名以不监视。尝试找到此文件并查看是否存在不存在的文件扩展名

回答by gauravsngarg

Android Repo- Same problem i faced- Corrected as below

Android Repo- 我面临同样的问题 - 更正如下

Somehow i added "/app" in .gitignore file. Now after deleting "/app"it worked.

不知何故,我补充说"/app" in .gitignore file。现在删除后"/app"它起作用了。

Please check your .gitignore.

请检查您的 .gitignore。

回答by HappyCoder

Deleting the .git/index file did the trick. Quite a frustrating error which I seem to come into contact when I clone skeleton modules into my zf2 project.

删除 .git/index 文件就成功了。当我将骨架模块克隆到我的 zf2 项目时,我似乎遇到了一个令人沮丧的错误。