Git:在频繁移动的基础上维护许多主题分支 [英] Git: maintaining many topic branches on a frequently-moving base

查看:114
本文介绍了Git:在频繁移动的基础上维护许多主题分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我日常的git工作流程中,我有很多主题分支,如下所示:

 
o - o-- o(t2)
/
o - o(t1)
/
o - o - o(主)
\
o --o - o(t3)

当我从上游拉时,

< (t2)
/
o - o(t1)
/
o - o - o - n - n - n(主)
\
o - o - o(t3)

我想要在新主人的顶部加入所有主题分支 rebase

 
o '--o' - o'(t2)
/
o' - o'(t1)
/
o - o - o - n- -n - n(主)
\
o' - o' - o'(t3)

目前我手工操作,使用 git rebase --onto 。在这种情况下,整个更新过程将是:

  $ git checkout master 
$ git pull
$ git rebase master t1
$ git rebase --onto t1 t2〜3 t2
$ git rebase master t3

在各种主题分支之间跳转并添加提交时,这会变得更加棘手。



在我的案例中,主题分支之间的依赖关系纯粹是树状的:没有分支依赖多于一个其他分支。 (我必须以某种特定的顺序最终获得上游依赖的修补程序,因此我会先选择该顺序)。

是否有任何工具可以帮助我管理此工作流程?我已经看过 TopGit ,但它似乎是与 tg patch 基于电子邮件的工作流程相关联,这与我无关。

解决方案

在git邮件列表上提出了几乎相同的问题:
立即重新分支多个分支......
链接的响应附有一个perl脚本,可以生成您需要的命令。



如果你想让这个脚本变得快速并避免踩到你的脚趾,也可以考虑使用 git-new-workdir 来设置如果你发现自己一遍又一遍地解决了相同的冲突,考虑启用 2010/03/08 / rerere.htmlrel =nofollow> git rerere



这是一个替代方案:

 #构建一个占位符提交,其所有主题均为父级。 
HEADS =$(git for-each-ref refs / heads / \ *)&&
MAGIC_COMMIT = $(echoMagic Octopus$'\\\
\\\
'$ HEADS|
git commit-tree \
$(git merge-base $(echo $ HEADS| sed's /。* //'))^ {tree} \
$(echo$ HEADS| sed's /。* //; s / ^ / - p / '))&&
git update-ref refs / hidden / all $ MAGIC_COMMIT

#立即重新整理所有内容。
git rebase --preserve-merges master refs / hidden / all

#解决冲突和所有爵士乐。

#更新重定位占位符的主题参考。
PARENT =
回显$ HEADS|
阅读HASH TYPE REF
do
let ++ PARENT
git update-ref -m'Mass rebase'$ REFrefs / hidden / all ^ $ PARENT$ HASH
完成


In my day-to-day git workflow, I have many topic branches, like so:

              o--o--o (t2)
             /
         o--o (t1)
        /
 o--o--o (master)
        \
         o--o--o (t3)

When I pull from upstream,

              o--o--o (t2)
             /
         o--o (t1)
        /
 o--o--o--n--n--n (master)
        \
         o--o--o (t3)

I want to rebase all my topic branches on top of the new master:

                        o'--o'--o' (t2)
                       /
                  o'--o' (t1)
                 /
 o--o--o--n--n--n (master)
                 \
                  o'--o'--o' (t3)

Currently I do this by hand, using git rebase --onto. In this scenario, the whole update process would be:

$ git checkout master
$ git pull
$ git rebase master t1
$ git rebase --onto t1 t2~3 t2
$ git rebase master t3

This gets even hairier when jumping between various topic branches and adding commits.

Dependencies between topic branches in my case are purely tree-like: no branch depends on more than a single other branch. (I have to eventually upstream dependent patches in some particular order, so I choose that order a priori.)

Are there any tools that can help me manage this workflow? I've seen TopGit, but it seems to be tied quite heavily to the tg patch email-based workflow, which isn't relevant to me.

解决方案

Pretty much the same question was asked on the git mailing list: Rebasing Multiple branches at once... The linked response has a perl script attached that generates the commands you would need.

If you want this script to be fast and avoid having it tread on your toes, also consider using git-new-workdir to set up a working copy just for automatic rebasing.

If you find yourself resolving the same conflicts over and over, consider enabling git rerere.

Having said all that, here is an alternate recipe:

# Construct a placeholder commit that has all topics as parent.
HEADS="$(git for-each-ref refs/heads/\*)" &&
MAGIC_COMMIT=$(echo "Magic Octopus"$'\n\n'"$HEADS" |
  git commit-tree \
    $(git merge-base $(echo "$HEADS" | sed 's/ .*//' ))^{tree} \
    $(echo "$HEADS" | sed 's/ .*//;s/^/-p /')) &&
git update-ref refs/hidden/all $MAGIC_COMMIT

# Rebase the whole lot at once.
git rebase --preserve-merges master refs/hidden/all

# Resolve conflicts and all that jazz.

# Update topic refs from the rebased placeholder.
PARENT=
echo "$HEADS" |
while read HASH TYPE REF
do
  let ++PARENT
  git update-ref -m 'Mass rebase' "$REF" refs/hidden/all^$PARENT "$HASH"
done

这篇关于Git:在频繁移动的基础上维护许多主题分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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