1

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.

Fed Zee
  • 391
  • 3
  • 8
  • 1
    Have you seen [this](http://stackoverflow.com/questions/37298548/same-files-listed-as-both-untracked-and-deleted) and [this](http://stackoverflow.com/questions/35909016/files-in-the-git-repo-are-both-deleted-and-untracked-but-theyre-still-there-ho)? – Julien Lopez Nov 07 '16 at 13:58
  • Thanks ! I have not found those threads indeed... I have searched however with many keywords, and even Github did not suggest me those obvious threads when I wrote my question. – Fed Zee Nov 09 '16 at 15:48
  • FYI: The command `git add --all` worked fine to add my files, while `git add -A` did not. It seems mysterious, because they are told to be equivalent, according to this interesting and popular post: http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add ... But it worked ! – Fed Zee Nov 09 '16 at 15:59
  • Hmmm, `-A` and `--all` **are** the same option. :-D Check out the [documentation](https://git-scm.com/docs/git-add). – Julien Lopez Nov 09 '16 at 16:17
  • Btw, can you give the output of `git config --get-regexp alias` in your git repository? – Julien Lopez Nov 13 '16 at 10:59

1 Answers1

0

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
Fed Zee
  • 391
  • 3
  • 8