Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

git - How to move bugfixes across branches in DVCS?

If we discover bug in some branche we fix it (check New release on picture). But also we interesting in moving this fix to Old release and Main development branch:

a-->b-->c              (Old release)
|    
A-->B-->C-->D           (Main release)
    |
    1-->2-->bugfix-->4  (New release)

svn remember in svn:merge properties (from svn 1.6, 2009) which revision merged to which branches. So next time if you merge region of revisions previously merged revisions was skipped from merge patch.

How deal with modern DVCS?

I need make plain patch and apply it to each branches or there are exist some help from DVCS?

Note: I can not just merge New branche to Main as previous changesets move also to Main branche.

Rebase also not possible as New release come to many developers.

I interesting in answer for named braches schema and for multirepository schema.

PS. Andy suggest find common parent to all branches for which bug have affect, update to it, apply fix to the bug and move fix to affected branches.

By updating to old changeset and making changes you create new branch. I recommend create named branch (name it as bugID), so later you can easy back to it.

There are problem on finding common parent to all branches in which we have interest to fix bug.

First solution (that suggest Andy) is using $ hg/git/bzr blame and carefully check output for all affected files. This involve first fix bug on some newest changeset before you find with blame what changeset introduce a bug. Then you need rebase fix (patch) to common parent changeset.

Another solution is using $ hg/git/bzr bisect (you can also manually perform updates to find first revision in which bug introduced). This can be expansive but more true solution as allow populate bugfix to any branches in which bug present.

I think it is better first find first BAD changeset and then fix a bug, instead of first fix a bug and then find first BAD changeset (except case when you already know how fix bug). Also having a diff that introduce can help in understanding why it occur.

PPS. With bugs it is clear which branch effected to allow merge changes to any effected branch.

Interesting question come if ask how backport feature from development branch to release branch. As you can see you must commit feature changesets starting with changeset that before release branch. But when you develop feature you can don't know where you need backport feature. With svn:merge VCS remember for you all backports. How about DVCS?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could:

  1. Find common parent. Thanks to Novelocrat for this step.
    git merge-base branch1 branch2 branch3 ...

  2. Checkout the common parent
    git checkout A

  3. create new branch to fix bugs on
    git checkout -b bugFix

  4. Make bug fixes and commit them to bugFix branch

  5. Checkout branch that needs the bug fix
    git checkout branchToApplyFixTo

  6. Merge the bugFix into the branch
    git merge bugFix


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...