本文介绍了Git不再将我的文件分级,并将它们报告为“已删除”和“未跟踪”。为什么是这样,以及如何避免它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

  $ git add ch28_NN.py 
$ git add Challenge28.py
$ git status
在分支大师
您的分支是最新的'origin / master'。
要提交的更改:
(使用git reset HEAD< file> ...停用)

删除:.gitignore
删除:Challenge28。 py
已删除:ch28_NN.py
已删除:requirements.txt

未记录的文件:
(使用git add< file> ...将承诺什么)

.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 $ b $分支主
    你的分支是最新的'origin / master'。
    要提交的更改:
    (使用git reset HEAD< file> ...停用)

    修改:Challenge28.py
    修改:ch28_NN .py

    $ git add Challenge28.py#CREATED BACK THE PROBLEM - 但它只删除了三个文件,并且它演出了一个(另一个案例在下面转录,使用相同的命令)
    $ git status
    在分支主机
    上你的分支是'origin / master'的最新版本。
    要提交的更改:
    (使用git reset HEAD< file> ...停用)

    删除:.gitignore
    修改:Challenge28。 py
    已删除:ch28_NN.py
    已删除:requirements.txt

    未经记录的文件:
    (使用git add< file> ...将承诺什么)

    .gitignore
    ch28_NN.py
    requirements.txt

    $ git add --all#再次重工!
    $ git status
    在分支大师
    您的分支是最新的'origin / master'。
    要提交的更改:
    (使用git reset HEAD< file> ...停用)

    修改:Challenge28.py
    修改:ch28_NN .py

    $ git add Challenge28.py#CREATED BACK THE PROBLEM - 但它删除了所有的四个文件...
    $ git status
    分支主
    您的分支与origin / master保持一致。
    要提交的更改:
    (使用git reset HEAD< file> ...停用)

    删除:.gitignore
    删除:Challenge28。 py
    已删除:ch28_NN.py
    已删除:requirements.txt

    未经记录的文件:
    (使用git add< file> ...将承诺什么)

    .gitignore
    Challenge28.py
    ch28_NN.py
    requirements.txt

    $ git add -A# DID不工作
    $ git status
    在分支大师
    上你的分支是最新的'origin / master'。
    要提交的更改:
    (使用git reset HEAD< file> ...停用)

    删除:.gitignore
    删除:Challenge28。 py
    已删除:ch28_NN.py
    已删除:requirements.txt

    未经记录的文件:
    (使用git add< file> ...将承诺什么)

    .gitignore
    Challenge28.py
    ch28_NN.py
    requirements.txt

    $ git add --all #WORKED FINE AGAIN ...
    $ git status
    在分支大师
    上您的分支与'origin / master'保持同步。
    要提交的更改:
    (使用git reset HEAD< file> ...停用)

    修改:Challenge28.py
    修改:ch28_NN .py


    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.

    解决方案

    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
    

    这篇关于Git不再将我的文件分级,并将它们报告为“已删除”和“未跟踪”。为什么是这样,以及如何避免它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:00