Git doesn't stage my files any longer, and reports them as both “deleted” and “untracked”. Why is that, and how to avoid it?

ぐ巨炮叔叔 提交于 2020-02-05 04:02:06

问题


I have been successfully working on a simple git repo, with 4 files, adding and committing them many times.

But lately, any time I try to add some of them, then ask for status, git reports all my files as deleted AND untracked. So I can not add my files.

$ 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

My only solution now would be to make backups and try to reset to unstage.

I would like to understand what went wrong, and how to avoid it.


回答1:


I eventually found a solution, which is not the one discussed in the two suggested (but interesting) links.

I found that :

  • Using git add --all worked fine to stage

  • Using git add -A did not work... even if it is supposed to be equivalent to the first

  • I still have the problem any time I add my file with the simple command git add filename, and I still resolve it by adding everything (git add --all) So it is a little bit of a hassle (for both being not handy, and remaining unexplained) but still I can go on with my work.

Here is the illustration of what worked, what did not, what recreated the problem, and what solved it back:

$ 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


来源:https://stackoverflow.com/questions/40466714/git-doesnt-stage-my-files-any-longer-and-reports-them-as-both-deleted-and-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!