简体   繁体   English

git 从带有子模块的 repo 中的先前提交创建新分支

[英]git create new branch from a previous commit in repo with submodules

I have a git repo with multiple submodules.我有一个带有多个子模块的 git 存储库。 On "master" branch of parent repo, lets say the history looks like A -> B -> C -> D -> E -> F (HEAD).在父仓库的“master”分支上,假设历史看起来像 A -> B -> C -> D -> E -> F (HEAD)。 My parent repo is setup such that the submodules are pointing to a detached HEAD (like this "HEAD detached at ").我的父 repo 设置为子模块指向一个分离的 HEAD(比如这个“HEAD detached at”)。 I want to go back to a previous commit on "master" branch of parent repo, commit "C" and update one of the submodules to a more recent commit and push this new state of the "master" branch of parent repo to remote.我想 go 回到父仓库的“master”分支上的先前提交,提交“C”并将其中一个子模块更新为更新的提交,并将父仓库的“master”分支的这个新 state 推送到远程。

How do I go about this?我该如何 go 关于这个?

I have the following steps but I am not sure if that these are the right steps.我有以下步骤,但我不确定这些步骤是否正确。

git reset --hard HEAD~3 (which takes me to commit C)
git submodule update --init
cd path/to/submodule ; git checkout <commit_id> ; cd -
git add path/to/submodule ; git commit
git push origin master

Is this the correct procedure?这是正确的程序吗? Would I need to use the --force option in the last step.我是否需要在最后一步中使用 --force 选项。 I looked up for similar question on how its done in a regular git repo without submodules but I am not sure of how to do it with repo with submodules.我查找了类似的问题,关于它如何在没有子模块的常规 git 仓库中完成,但我不确定如何使用带有子模块的仓库来做到这一点。 New to working with submodules.使用子模块的新手。

My parent repo is setup such that the submodules are pointing to a detached HEAD我的父仓库设置为子模块指向一个分离的 HEAD

Well, it's hardly "setup".好吧,这几乎不是“设置”。 Detached HEAD is the natural state of submodules.分离的 HEAD 是子模块的自然 state。 Most of the time most submodules are in detached HEAD state except when you deliberately fix it;大多数情况下,大多数子模块都处于分离的 HEAD state 中,除非您故意修复它; and even with manual fixes they will probably switch to detached HEAD rather soon.即使通过手动修复,它们也可能很快就会切换到分离的 HEAD。

Is this the correct procedure?这是正确的程序吗?

Yes, looks good.是的,看起来不错。

Would I need to use the --force我需要使用 --force

Yes because you move the branch pointer in a non-fast-forward way.是的,因为您以非快进方式移动分支指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM