【问题标题】:Unable to do "git add ."无法执行“git add”。
【发布时间】:2013-08-13 19:28:27
【问题描述】:

我能够将我的目录添加到 git 并执行 git commit 但奇怪的是,当我这样做时

$ git add .

我收到以下错误:

warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in grails-app/controllers/com/abc/pqr/Rep
ortController.groovy.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in grails-app/domain/com/abc/pqr/Report.g
roovy.
The file will have its original line endings in your working directory.
fatal: unable to stat 'Dirname#com.abc.pqr.Report': No such file or directo
ry

我已经通过this SO 回答,如果我尝试:

$ git rm Dirname#com.abc.pqr.Report

我收到此错误:

fatal: pathspec 'Dirname#com.abc.pqr.Report' did not match any files

令人惊讶的是,在搜索上述目录时没有文件,我没有找到上述任何此类文件。

值得一提的是,根目录下有一个文件Dirname/#com.abc.pqr.Report(即根目录下Dirname下的文件#com.abc.pqr.Report)。奇怪的是我无法删除,一个类似于this(我使用的是windows-7 os)的问题,我可以使用this解决它。但是自从我(不小心通过一个错误的grails脚本)创建了上面文件,我无法执行 `git add 。

【问题讨论】:

  • Dirname#com.abc.pqr.Report 是悬空链接吗?向我们提供有关该文件的更多详细信息。
  • @GregBacon 什么是“悬空符号链接”?
  • @GregBacon 根据我对“悬空符号链接”和 ubuntuforums.org/showthread.php?t=1078729 的理解,是的,它似乎是一个。但是我在 Windows 上使用它,但 git bash 似乎是基于 linux 的。
  • ls -l 'Dirname#com.abc.pqr.Report' 的输出是什么?
  • @GregBacon 没有这样的文件或目录

标签: git filesystems git-add


【解决方案1】:

如果您不希望 Dirname#com.abc.pqr.Report 成为您提交的一部分,请暂存您要做明确想要的更改。例如:

$ git add .idea/workspace.xml
$ git add grails-app/controllers grails-app/domain
...

以上命令假定Dirname#com.abc.pqr.Report 不在指定目录之一中。如果是,则在您可以指定的地方命名顶级目录,并在强制时具体说明。

使用git add 暂存所有更改后,您可以使用git commit 安全地提交它们。

【讨论】:

  • 这似乎是答案但是从现在开始,我需要分别添加每个目录。所以说我在 10 个不同的文件中修改 100 个不同的文件,那么我将不得不做 10 次 git 添加,这很乏味。简而言之,我将无法执行“git add”。再次。我希望永久摆脱这个“悬空符号链接”
  • 以上是一种解决方法。解决方法是弄清楚如何删除该文件。
  • 因为你的答案有效,而且无论如何我已经能够至少推动我当前的提交,所以我赞成你的答案。但我仍然会等待得到最终的解决方案。
【解决方案2】:

在 Unix 系统中,行尾用换行符表示:LF。在 Windows 中,一行用回车符表示:CR 和换行符:LF(CRLF)。因此,如果您尝试从 linux 添加文件,那么它只有 LF,因此会显示警告。没什么好担心的。无论如何,我认为git add . 命令会添加您的文件。只需执行 git status 并验证它是否已添加。

【讨论】:

  • "无论如何我认为 git add . 命令会添加你的文件。"不,它没有被提交并显示“没有添加到提交的更改(使用“git add”和/或“git commit -a”)”
  • 嗯。我会检查并告诉你。顺便说一句,使用正确的文件路径尝试$ git rm Dirname#com.abc.pqr.Report。我不认为这是正确的Dirname#com.abc.pqr.Report
  • 我无法访问该文件,因为我已经删除了整个结构。最初在根目录 (.) 内的目录 Dirname 中有 #com.abc.pqr.Report。我删除了整个 Dirname 目录及其内容。那么,由于一个文件中的错误,它没有添加任何要跟踪的文件,这不是 git 中的错误吗?
猜你喜欢
  • 2017-04-20
  • 2014-08-01
  • 2021-09-12
  • 2011-07-07
  • 1970-01-01
  • 2016-03-26
  • 2013-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多