当前位置: 动力学知识库 > 问答 > 编程问答 >

git - Checking out a branch that manages a path with a submodule when the original branch does not

问题描述:

I created a branch in which I converted a path in my repository to a submodule. I haven't merged that work into master yet. Having finished converting that path to a submodule, I attempted to switch back to master and got the following error:

The following untracked working tree files would be overwritten by checkout:

[ ... a list of files that are now being managed by a submodule ...]

Makes sense. So, I did git checkout --force master. Then, when I switched back to the branch that tracks the path with a submodule, that path was empty except for the .git pointer find that you find in submodules. To get the submodule re-checked out to the commit designated in the index, I need to do git submodule update --force.

Is there a simpler way to handle this situation?

网友答案:

As long as you keep a directory:

  • as a submodule in one branch
  • as a set of managed files in master

You will have the kind of experience you saw, since git submodule update isn't automatic.

One workaround would be to maintain two clones (one on master, one on your branch).

The other would be to setup a post-checkout hook which would:

  • detect the checked out branch
  • do the git submodule update --force is appropriate.

Something along the lines of that hook (or this one).

分享给朋友:
您可能感兴趣的文章:
随机阅读: