首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >git:当两个人正在更新一个子模块(两个遥控器)时,我该如何处理它?

git:当两个人正在更新一个子模块(两个遥控器)时,我该如何处理它?
EN

Stack Overflow用户
提问于 2022-11-11 20:26:57
回答 1查看 15关注 0票数 1

我有一个依赖于git子模块的项目。子模块也是我拥有的存储库,但是是从另一个用户的github存储库中克隆出来的。

代码语言:javascript
复制
The layout is:
      my_project/
         my_submodule/

我想让我的子模块主分支保持干净,并且(可选)同步到其他用户的github存储库(它的主分支也是),这样我就不会搞砸它。但是我想在我自己的子模块的新分支中创建新的分支和新的提交,这样我就可以将PRs发送到github,并有一个"all_commits“分支,该分支保存了对子模块的所有更改,这样我就可以使用最新版本的my_project检查更改。基本上,我期待的是这个工作流:

代码语言:javascript
复制
$ cd my_submodule/
$ git switch main
$ git branch new_pr
$ git checkout new_pr
$ emacs somefile.cpp  # change some file
$ git commit -a
$ git push -u origin new_pr
$ git switch all_commits
$ git merge new_pr     # so all_commits holds all my prs and changes

一旦公共关系被接受:

代码语言:javascript
复制
$ cd my_submodule
$ git switch main
$ git "sync" to orig_main  # this is the command I am missing
$ git push -u origin main  # store the new_pr change in my own repository
$ git branch -D new_pr     # remove the new_pr now that it was accepted
EN

回答 1

Stack Overflow用户

发布于 2022-11-12 01:06:18

缺少的一个步骤是用原始存储库刷新主分支(“其他用户的github存储库”)

代码语言:javascript
复制
$ cd my_submodule/
$ git switch main

$ # if not already done
$ git remote add upstream https://url/other/user/repo

$ git fetch upstream
$ # reset main to the other user's repo main branch
$ git switch -C main upstream/main
$ # create a new PR based on the latest from upstream/main:
$ git switch -c new_pr
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74407772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档