1

我已经成功地处理了一个简单的 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

我现在唯一的解决方案是进行备份并尝试重置为 unstage。

我想了解出了什么问题,以及如何避免它。

4

1 回答 1

0

我最终找到了一个解决方案,这不是两个建议的(但有趣的)链接中讨论的解决方案。

我找到 :

  • 使用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
于 2016-11-09T16:29:56.520 回答