Git 不再暂存我的文件,并将它们报告为 "deleted" 和 "untracked" 。为什么会这样,以及如何避免呢?



我已经成功地完成了一个简单的git repo,有4个文件,添加并提交了很多次。

但是最近,每当我尝试添加一些文件,然后询问状态时,git都会报告我所有的文件为已删除和未跟踪。所以我不能添加我的文件。

$ git add 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 --all工作良好的阶段

  • 使用git add -A不工作…即使它应该相当于第一个

  • 我仍然有问题,任何时候我用简单的命令git add filename添加我的文件,我仍然通过添加一切(git add --all)来解决它,所以它有点麻烦(既不方便,又无法解释),但我仍然可以继续我的工作。

下面的例子说明了哪些是有效的,哪些是无效的,哪些重现了问题,以及哪些解决了问题:

$ git add --all           # WORKED FINE
$ 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           # CREATED BACK THE PROBLEM - but it deleted only three files and it staged one (an other case is reproduced below, with the same command)
$ 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           # WORKED FINE AGAIN !
$ 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           # CREATED BACK THE PROBLEM - but it deleted all the four files... 
$ 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           # DID NOT WORK 
$ 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           # WORKED FINE AGAIN...
$ 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

最新更新