Search code examples
gitgit-submodules

Git: Is it possible to make branch use specific version of submodule


Git pipeline is failing due to missing commit in one of submodules. It is not possible to recover that commit because it was lost during hardware crash. How can we make a branch use older version (commit) of submodule, even after we have the newer version in commit history?


Solution

  • If the submodule is a real submodule registered in .gitmodules then you should do this in a local worktree:

    cd <superproject>
    git checkout <abranch>
    cd <submodule_path>
    git checkout <old_commit>
    cd <superproject>
    git add <submodule_path>
    git commit -m "Update submodule"
    git push