2016-11-07 22 views
1

我已經成功地開發了一個簡單的git倉庫,有4個文件,多次添加並提交它們。但最近,任何時候我嘗試添加其中的一些,然後詢問狀態,git會將所有文件報告爲已刪除和未跟蹤。所以我不能添加我的文件。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 

我現在唯一的解決方法是做備份並嘗試重置爲非活動狀態。

我想了解哪裏出了問題,以及如何避免它。

+1

你見過[這](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-既缺失,和未跟蹤,但是,更有耐力,仍然有浩)? –

+0

謝謝! 我的確沒有找到那些線索......但是我用很多關鍵字搜索過,甚至Github在寫我的問題時都沒有向我建議那些明顯的線索。 –

+0

僅供參考:命令'git add --all'可以很好地添加我的文件,而'git add -A'沒有。 這似乎很神祕,因爲他們被告知是等效的,根據這個有趣的和受歡迎的帖子:http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add 。 ..但它的工作! –

回答

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 
相關問題