Search code examples
gitgit-mergegit-submodulesgit-commitgit-pull

Git submodules reference is not a tree


A developer here ran the steps we recommend for git usage, and has lost a submodule commit. I understand that this error means that she pushed in the super project but not in the submodule, but she denies this and has a history of her commands that she showed me. Here are the steps that seemed to have caused this. I would like to understand how to tell her to avoid this in the future.

  • She committed in the submodule and in the superproject.
  • she pulled in the latest on her branch. This caused a submodule conflict with no real content conflicting
  • she ran git commit -a in the superproject to resolve it. (It would be helpful to understand this type of conflict too).
  • She ran a merge from another branch and committed in both places.
  • She ran a global push which cds into each submodule, runs push and then runs push in the superproject.

At this point, her work committed in the original commit in the submodule disappeared from git log.


Solution

  • I suppose the commit was lost when she solved the submodule conflict. It can be retrieved by following instructions in this question.

    Or run

    gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
    

    (This is from this question)

    Only do it on the original repo (as git clone will delete dangling commits), and make a backup of it before.