Git: fatal: Pathspec is in submodule

后端 未结 5 1731
感情败类
感情败类 2020-12-02 05:04

I\'m trying to get TravisCI to automatically deploy my Hakyll static site, according to this guide.

Here\'s how my repo is set up. I have my source branch, which con

相关标签:
5条回答
  • 2020-12-02 05:12

    100% fix for this problem, even if you have more than one submodule directory inside the project:

    > git submodule foreach --recursive deinit -f --all -- <relative path>
    > git add --all -f
    
    0 讨论(0)
  • 2020-12-02 05:18

    It seems my problem is that I was accidentally deleting the .git folder of the submodule.

    0 讨论(0)
  • 2020-12-02 05:22

    It sounds like you're operating on non-initialized submodules (they're basically missing .git directories), therefore you should initialize them first and update:

    git submodule init
    git submodule update
    

    Otherwise if you don't need this submodule anymore, remove it by:

    git submodule deinit _site
    

    or:

    git rm -f --cached _site
    

    and add it again:

    git add _site
    

    Check your current outstanding submodules by: git submodule status.

    See also: Why is git erroring with 'Assertion failed' on git add .?

    0 讨论(0)
  • 2020-12-02 05:29

    It seems the git add context is the parent repo ("parent" means the one including the submodule), which triggers the warning.

    Try and change its context with:

    cd _site
    git --git-dir=.git --work-tree=. add . 
    git --git-dir=.git --work-tree=. commit -m "new files"
    

    Don't forget that, if this works, you would still have to go back to the parent repo, and git add _site, since the subrepo would have changes.

    And you would have to push both.


    Update January 2017 (2+ years later)

    With Git 2.12, you won't see that prefix_pathspec: Assertion anymore.

    See commit 2d81c48 (09 Jan 2017) by Stefan Beller (stefanbeller).
    Helped-by: Jeff King (peff), and Junio C Hamano (gitster).
    (Merged by Junio C Hamano -- gitster -- in commit 00880a1, 18 Jan 2017)

    pathspec: give better message for submodule related pathspec error

    Running "git add a/b" when "a" is a submodule correctly errored out, but without a meaningful error message.

    0 讨论(0)
  • 2020-12-02 05:35

    Removing the directory from git and adding it again worked for me:

     git rm --cached directory
     git add directory
    

    This works if you purposefully removed the .git directory because you wanted to add directory to your main git project. In my specific case, I had git cloned an extension and ran git add . without thinking too much. Git decided to create a submodule, which I didn't like. So I removed directory/.git and ran into Git: fatal: Pathspec is in submodule. I couldn't find out how to remove the submodule stuff. Fixed with the two lines above.

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