[英]Git checkout when using submodules
I have a parent git repo with 3 branches in it. 我有一个3个分支的父git repo。 I am also using a submodule repo, that has the 3 branches with the same names, and the .gitattributes file in each branch of the parent repo points to the submodules branch of the same name. 我还使用了一个子模块存储库,该子模块存储库具有3个具有相同名称的分支,并且父存储库的每个分支中的.gitattributes文件都指向相同名称的子模块分支。 This is all well and good, but the question I have is, when I do a git checkout BRANCH in the parent repo, I always have to do a git submodule update after, or the files in the submodule directory wont be updated to reflect the correct branch 这一切都很好,但是我的问题是,当我在父仓库中执行git checkout BRANCH时,我总是必须在之后进行git子模块更新,否则子模块目录中的文件将不会更新以反映正确的分支
Is there a simple way to automate this, so that every time I do a checkout the submodule files get updated to reflect the correct branch? 有没有一种简单的方法可以自动执行此操作,以便每次我结帐时都会更新子模块文件以反映正确的分支?
git checkout master & git submodule foreach git checkout master
Where master
is the name of your chosen branch master
是您选择的分支的名称
You can add a hook
post-checkout
and do this action whenever you call git checkout
automatically. 您可以添加一个hook
post-checkout
并在每次自动调用git checkout
时执行此操作。 You need to create a file .git/hooks/post-checkout
which will look like: 您需要创建一个文件.git/hooks/post-checkout
,看起来像:
branch=$(git rev-parse --symbolic --abbrev-ref $1)
git submodule foreach git checkout $branch
Hope this will help 希望这会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.