Git will not init/sync/update new submodules

后端 未结 21 1984
野趣味
野趣味 2020-12-12 13:11

Here\'s part of the contents of my .gitmodules file:

[submodule \"src/static_management\"]
        path = src/static_management
        url = gi         


        
相关标签:
21条回答
  • 2020-12-12 13:54

    For the record:
    I created the same issue by adding an empty repository as submodule. In this case, there was no reference hash available for the submodule, leading to the error described by the original poster.

    Force-adding the repository after having committed to it solved the issue (as in Arvids post)
    git submodule add --force git@my-repo.git destination

    0 讨论(0)
  • 2020-12-12 13:54

    When I saw this today, a developer had moved part of the tree into a new sub-directory and it looks as though his git client did not record the updated Subproject rules in the tree, instead they were just nuked, leaving .gitmodules referring both to stale locations and to subprojects which no longer existed in the current tree.

    Adding the submodules back in, and comparing the commit shas of the submodule to those found in git show $breaking_commit_sha (search for lines matching regexp ^-Subproject) to adjust as needed fixed things.

    0 讨论(0)
  • 2020-12-12 13:56

    Same as you I found that git submodule sync does not do what you expect it to do. Only after doing an explicit git submodule add again does a submodule url change.

    So, I put this script in ~/bin/git-submodule-sync.rb:

    https://gist.github.com/frimik/5125436

    And I also use the same logic on a few post-receive git deploy scripts.

    All I need to do now is edit .gitmodules, then run this script and it finally works like I thought git submodule sync was supposed to.

    0 讨论(0)
  • 2020-12-12 14:00

    Thinking that manually setting up .gitmodules is enough is WRONG

    My local git version 2.22.0 as of this writing.

    So I came to this thread wondering why wasn't git submodule init working; I setup the .gitmodules file and proceeded to do git submodule init ...

    IMPORTANT

    1. git submodule add company/project.git includes/project is required (when adding the module for the first time), this will:

      • add config to .git/config
      • update the .gitmodules file
      • track the submodule location (includes/project in this example).
    2. you must then git commit after you have added the submodule, this will commit .gitmodules and the tracked submodule location.

    When the project is cloned again, it will have the .gitmodules and the empty submodules directory (e.g. includes/project in this example). At this point .git/config does not have submodule config yet, until git submodule init is run, and remember this only works because .gitmodules AND includes/project are tracked in the main git repo.

    Also for reference see:

    • How do I remove a submodule?
    • How do I move an existing submodule?
    0 讨论(0)
  • 2020-12-12 14:02

    I had a similar problem with a submodule. It just didn't want to be cloned/pulled/updated/whatever.

    When trying to re-add the submodule using git submodule add git@my-repo.git destination I got the following output:

    A git directory for 'destination' is found locally with remote(s):
      origin        git@my-repo.git
    If you want to reuse this local git directory instead of cloning again from
      git@my-repo.git
    use the '--force' option. If the local git directory is not the correct repo
    or you are unsure what this means choose another name with the '--name' option.
    

    So, I tried to enforce the add command:
    git submodule add --force git@my-repo.git destination

    That worked in my case.

    0 讨论(0)
  • 2020-12-12 14:02

    Below sync command resolved the issue :

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