【问题标题】:Same files listed as both untracked and deleted相同的文件被列为未跟踪和已删除
【发布时间】:2016-09-14 21:03:23
【问题描述】:

在 Git 存储库中运行 git status,我得到:

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    path/to/file1.sql 
        deleted:    path/to/file2.sql 
        deleted:    path/to/file3.sql 

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        path/to/file1.sql
        path/to/file2.sql
        path/to/file3.sql

no changes added to commit (use "git add" and/or "git commit -a")

所有其他文件都很好。 我已经尝试过重置、签出等,还再次克隆了存储库(我们使用集中式服务器)。没有什么能解决问题,但仅适用于使用 Windows 的特定用户。 Linux 上没有出现此问题。

附加信息:

  • git diff 没有显示输出。
  • 我已经尝试将 core.autocrlf 设置为 false。

【问题讨论】:

  • 这肯定没有行尾问题,因为这样文件只会显示为已修改,而不是已删除且同时未跟踪。我更怀疑这里有套管问题。路径真的相同吗,还是大写/小写有区别?
  • 向我们展示你的 .gitignore 和git log -- path/to/file1.sql path/to/file2.sql path/to/file3.sql的输出
  • 这是在您对工作目录进行更改之后,还是在签出分支/克隆存储库时立即发生?
  • 版本信息(适用于 Git 和 Windows)在这里可能很重要。 (我不知道发生了什么,只是提供更多信息的建议。)
  • 在我的情况下,git diff 显示了一些结果,但似乎是将文件上移了一个目录的结果,git rm 解决了问题

标签: git file


【解决方案1】:

这实际上是一件非常简单的事情:文件已在文件名的end 处提交了一个空格。 显然 Windows 无法处理这个问题,并且每次都会自动删除空间(克隆后,结帐后等)。

所以 Git 显示了正确的信息,文件 "path/to/file1.sql " 已被删除,文件 "path/to/file1.sql" 是新的(抱歉,问题中没有显示,现在我更正它以显示示例 Git 输出)。

一开始我没有注意到这一点,因为在看到git status 在那里很好之后,我只是在Linux 上lsed 目录/path/to/ 的内容,并尝试在Windows 中调试所有内容(不可能,除非您通过选择 Git 输出的正确部分以某种方式注意到该空间)。 由于Vampire's comment,我对文件名(在Linux上)进行了额外检查,但我得到了奇怪的结果

ls /path/to/file1.sql
ls: file not found

在按 TAB 并看到 "/path/to/file1.sql\ " 后,我想通了。 我认为这个问题很简单,但是由于每天都不会发生有人提交名称末尾有空格的文件,我认为可能需要一段时间才能确定 Git 没有真正的问题。

所以我现在将留下问题和答案,如果您不同意,只需投反对票,我将删除所有内容。

感谢所有在 cmets 中提供帮助的人。

【讨论】:

    【解决方案2】:

    我有一个非常相似的问题,在这里讨论Git doesn't stage my files any longer, and reports them as both "deleted" and "untracked". Why is that, and how to avoid it?

    我发现:

    • 使用git add --all 可以很好地上台

    • 使用git add -A 不起作用...即使它应该等同于第一个

    • 放置空格可能是您的问题,但这不是导致我的问题的原因 :( 它仍未解决。仅供参考,我正在使用 Mac OS 10.10

    • 每当我使用简单的命令git add filename(没有空格)添加文件时,我仍然遇到问题,并且仍然通过添加所有内容来解决它(git add --all)所以这有点麻烦(因为既不方便,又无法解释)但我仍然可以继续我的工作。

    以下是什么有效、什么无效、什么重现了问题以及什么解决了问题的说明:

    $ git add --all
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        modified:   Challenge28.py
        modified:   ch28_NN.py
    
    $ git add Challenge28.py
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        deleted:    .gitignore
        modified:   Challenge28.py
        deleted:    ch28_NN.py
        deleted:    requirements.txt
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
        .gitignore
        ch28_NN.py
        requirements.txt
    
    $ git add --all
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        modified:   Challenge28.py
        modified:   ch28_NN.py
    
    $ git add Challenge28.py
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        deleted:    .gitignore
        deleted:    Challenge28.py
        deleted:    ch28_NN.py
        deleted:    requirements.txt
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
        .gitignore
        Challenge28.py
        ch28_NN.py
        requirements.txt
    
    $ git add -A
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        deleted:    .gitignore
        deleted:    Challenge28.py
        deleted:    ch28_NN.py
        deleted:    requirements.txt
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
        .gitignore
        Challenge28.py
        ch28_NN.py
        requirements.txt
    
    $ git add --all
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        modified:   Challenge28.py
        modified:   ch28_NN.py
    

    【讨论】:

      猜你喜欢
      • 2017-05-10
      • 1970-01-01
      • 2018-06-23
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 2017-04-01
      相关资源
      最近更新 更多