使用 Git 将 master 的更改合并到所有分支中?

发布于 2024-08-23 01:09:54 字数 368 浏览 5 评论 0原文

我使用 git 维护代码的多个工作副本。我的想法是,我可以检查任何分支,构建并运行它,以查看分支的功能 x 如何适应代码的当前状态。

Git 的主分支是主干,其他 git 分支是我想尝试的功能或东西。因此,我的典型用法是使用最新的修复程序更新 master,然后将 master 合并到各个分支中,以便每个分支都保持最新状态。

这个系统对我来说效果很好,除了我必须签出一个分支,合并主分支并冲洗/重复其他分支这一事实。考虑到像 git 这样的版本控制系统,考虑到随着时间的推移我很容易产生大量分支,我看不到这种扩展效果。

我仍然是一个 git 初学者,所以我怀疑 git 已经拥有某种机制,但我可能会丢失。有吗?如果不是,如何对所有分支进行更改,以便它们自己保持最新状态?

I use git to maintain multiple working copies of my code. The idea is that I can check out any branch, build and run it to see how the branch's feature x fits in with the current state of the code.

Git's master branch is the Trunk and the other git branches are features or things I would like to try out. Therefore, my typical usage is updating the master with the latest fixes and then merging master into the individual branches so each of them stays up to date.

This system works well for me, except for the fact that I have to checkout a branch, merge the master and rinse/repeat for the other branches. Given a version control system like git, I don't see this scaling very well given the fact that I'd be prone to spawning a lot of branches over time.

I'm still a git beginner, so I suspect there may be a mechanism of sorts that git already has that I might be missing. Is there one? If not, how does one commit a change to all branches so they stay up to date on their own?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅忆 2024-08-30 01:09:54

如果

  1. 您想要合并最新 master 提交的分支未发布,并且
  2. 您希望 master 中的所有提交都位于其他分支中,

那么您可以在 master 更新后将它们重新设置为 master 。如果您使用的是 Unix shell,这个小脚本可能会起作用。它将每个分支重新建立到主分支上。

for BRANCH in `ls .git/refs/heads`; do git rebase master $BRANCH; done

If

  1. the branches which you want to merge the latest master commits into are not published AND
  2. you want all commits in master to be in the other branches

then you could simply rebase them onto master after master has been updated. This little script might work if you're using a Unix shell. It rebases each branch onto master.

for BRANCH in `ls .git/refs/heads`; do git rebase master $BRANCH; done
挖鼻大婶 2024-08-30 01:09:54

一种可能性(我自己没有测试过)是:

  • 建立一个裸仓库,您可以在其中推送主分支。
  • 有一个接收后挂钩(请参阅 githooks 手册页)在那个裸存储库上,然后将主控推送到您希望每个功能存储库
  • 都有一个接收后挂钩的每个“功能”存储库上:
    • 在 master 之上对功能分支进行变基(如果您尚未将功能分支推送到其他地方就可以了)
    • 或者在您的功能分支上合并 master。

您仍然需要访问您的功能存储库并检查变基或合并是否不会由于某些合并冲突而被阻止。

One possibility (not tested myself) would be:

  • to establish a bare repo where you can push your master branch.
  • have a post-receive hook (see githooks man page) on that bare repo which will then push master on every "feature" repo you want
  • have a post-receive hook per feature repo to begin:
    • a rebase of your feature branch on top of master (fine if you did not yet pushed your feature branch elsewhere)
    • or a merge of master on your feature branch.

You will still need to get to your feature repo and check if the rebase or merge is not blocked due to some merge conflicts.

残龙傲雪 2024-08-30 01:09:54

下面检查每个分支并进行合并

for BRANCH in $(ls .git/refs/heads);
  do git checkout $BRANCH ; 
  git merge origin/master $BRANCH ; 
done

The following checks out each branch and does the merge

for BRANCH in $(ls .git/refs/heads);
  do git checkout $BRANCH ; 
  git merge origin/master $BRANCH ; 
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文