Git:找出哪个分支包含提交并检出? [英] Git: Find out which branch contains a commit and check it out?

查看:98
本文介绍了Git:找出哪个分支包含提交并检出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处有关子模块的知识中,我现在可以使用来将子模块回滚到正确的提交

From what I've learned here about submodules, I can now roll my submodules back to the right commit by using

git submodule update --recursive

但是,现在子模块从不(很少?)在分支中.我认为,该子模块所需的分支没有存储.无论如何,我可以使用

however, now the submodules are never (rarely?) in a branch. I think that which branch the submodule needs is not stored. Anyway, I can use

git branch --contains HEAD

子模块中的

并找出分支,然后切换到该分支.有内置的方法吗?我的目标是回到包含提交的分支(如果有的话).

in the submodule and figure out the branch and then switch to it. Is there a built-in way to this? My goal is to get back to a branch that contains the commit (if there is one).

推荐答案

默认情况下,Git不按分支跟踪子模块,而是按提交跟踪子模块.因此,git submodule update将导致子模块处于分离的HEAD状态(类似于如果您git checkout特定的提交哈希).在进行任何工作之前,您必须确保实际签出一个分支,否则事情可能会变得混乱.

By default, Git doesn't track submodules by branches, it tracks them by commits. So git submodule update will result in the submodules being in a detached HEAD state (similar to if you git checkout a specific commit hash). Before doing any work, you'll have to make sure to actually check out a branch, otherwise things could get messy.

从Git 1.8.2开始,您现在可以使子模块跟踪分支.添加子模块时需要指定此选项:

As of Git 1.8.2, you can now have submodules track branches. This option needs to be specified when you add the submodule:

git submodule add -b master <git repo url>

如果您通过分支跟踪子模块,则需要将--remote添加到更新调用中:

If you track submodules via branches, you'll want to add --remote to the update call:

git submodule update --remote

您可以通过分支此处 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆