Git: maintaining many topic branches on a frequently-moving base

后端 未结 3 606
时光取名叫无心
时光取名叫无心 2020-12-28 15:59

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)
              


        
相关标签:
3条回答
  • 2020-12-28 16:27

    Don't rebase. Start your features from a common point. Merges are way less work in the end.

    This is what we do:

    http://dymitruk.com/blog/2012/02/05/branch-per-feature/

    0 讨论(0)
  • 2020-12-28 16:28

    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
    
    0 讨论(0)
  • 2020-12-28 16:30

    There's a new tool that allows to automate such tasks: git-assembler

    Here's a direct link to the example in the documentation for rebasing local branches

    You shouldn't dismiss TopGit immediately though. The ability to generate email patches is entirely optional.

    0 讨论(0)
提交回复
热议问题