Git submodule add: “a git directory is found locally” issue

后端 未结 6 1311
南旧
南旧 2020-12-22 15:10

I\'m actually trying to learn how to use git, including the git submodule subcommands. I already set up a server on which I can host, push and pull git reposito

相关标签:
6条回答
  • 2020-12-22 15:25

    i tried jbmilgrom's solution, specifically i tried git rm --cache and that didn't work for me either as the directory/submodule wasn't there. What worked for me was:

    1. rm -rf .git/modules/blah
    2. git submodule add git://path.to.new

    I did this after trying --force within the git submodule commands and rm all the other directories, pushes to master etc... the directory didn't exist and there was no reason for the cache. Turns out in .git/modules that is where this error was lying.

    0 讨论(0)
  • 2020-12-22 15:30

    You may have deleted your 'projets/fdf' from disk, but your Git repository still has it. Use git rm -rf projets/fdf to remove it from Git, then commit the changes. After that you'll be able to add this folder as a submodule.

    0 讨论(0)
  • 2020-12-22 15:37

    If you already deleted the submodule directory, like I did, follow the rest of jbmilgrom's instructions. The key is rm -rf .git/modules/path_to_submodule but go ahead and backup your whole parent repo directory first.

    If you only had one submodule just delete .gitmodules

    0 讨论(0)
  • 2020-12-22 15:37

    These two commands works for me.

    rm path/to/submodule -rf
    rm .git/modules/path/to/module -rf
    
    0 讨论(0)
  • 2020-12-22 15:39

    I came to this SO post trying to add a submodule with the same path as a submodule that I recently deleted.

    This is what ultimately worked for me (this article helped out a lot):

    If you haven't already run git rm --cached path_to_submodule (no trailing slash) as well as rm -rf path_to_submodule, do that!

    Then:

    1. Delete the relevant lines from the .gitmodules file. e.g. delete these:

      [submodule "path_to_submodule"] path = path_to_submodule url = https://github.com/path_to_submodule

    2. Delete the relevant section from .git/config. e.g. delete these:

      [submodule "path_to_submodule"] url = https://github.com/path_to_submodule

    3. rm -rf .git/modules/path_to_submodule

    Then, you can finally:

    git submodule add https://github.com/path_to_submodule

    0 讨论(0)
  • 2020-12-22 15:39

    You can do this while cloning your submodule:

    git submodule add --name submodule_name submodule path

    This will add your submodule into your project and will be added as a structure under .gitmodules file.

    And then if you don't want the older one you can remove it from .gitmodules structure and delete the submodule folder from the project.

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