Unable to add folder to git repo

前端 未结 2 610
梦如初夏
梦如初夏 2021-01-28 13:37

I think this issue has already been discussed under this question :

Recursively add the entire folder to a repository

However I still can not add some folders t

相关标签:
2条回答
  • 2021-01-28 14:10

    The long answer above is great but the TL;DR to fix it is:

    1. remove the .git repo of the sub-repo
    2. Run git rm -r --cached .
    3. Run git add .

    then git status should show you the folder added

    0 讨论(0)
  • 2021-01-28 14:28

    Whenever you see:

    modified: some-name (modified content)
    

    in git status output, this means that your Git repository thinks that the directory named some-name is part of some other Git repository. (Note that the sub-directory / folder name here, some-name in this example, does not end with a slash.)

    One way that I find helpful to think about this issue is to pretend that there are multiple Gits involved (because there are): one is your Git, working in your repository, and the other in this case is the folder or subdirectory's Git, working in this second Git repository. And it is—or at least was—a second Git repository, at some point.

    This bears repeating: this sub-directory / folder really was some other Git repository before. It may or may not still be a second repository. Moreover, your own Git repository has already recorded the presence of the other Git in some way. If your Git repository had not recorded that, you would have seen:

    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            subgit/
    

    Instead, though, you are seeing:

    Changes not staged for commit:
    ...
            modified:   subgit (modified content)
    

    So, the fact that your Git repository's git status output says modified content or untracked content means your repository is quite certain that this sub-directory is some other repository. Your repository is reporting the relative state of the other repository.

    You can get another hint about this if you use git status -uall, or git status --untracked-files=all (these mean the same thing, -u is short for --untracked-files=): if your Git doesn't think the sub-directory contains another Git repository, it will look inside the sub-directory and tell you about each file in the directory. If your Git is convinced that the sub-directory is a Git repository of its own, it won't look inside it and report each file—but your Git also won't say "modified content" or "untracked content" like this.

    What to do about this depends on what you want to happen in the end

    First, we need to talk about submodules.

    Submodules

    Git has a concept called submodules. Some people call them sob-modules because they make programmers cry.

    0 讨论(0)
提交回复
热议问题