Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging selected changes

[I tagged my question for mercurial but, really, I'm asking a conceptual question that applies to other source control apps, too.] Suppose you have a folder with application source code under version control; call it the main trunk. I clone the repository and start modifying the code, working on a new version of the program, committing revision after revision that will never be part of the main trunk.

Then one day, working on revision 23, I find a bug.

I commit it, as revision 24.

I want you to have my bug fix, without all the other changes I've made. What's the general procedure for pushing or merging just revision 24's code, the bug fix, back to the main trunk?

like image 504
Al C Avatar asked Aug 13 '26 18:08

Al C


1 Answers

In Mercurial, you have several options (and I'm certain that other DVCS's have similar capabilities)

The simplest method: once you realize that the bug belongs on the mainline trunk, you update to the mainline tip, commit, push, and then merge that changset into your side project.

hg up -r mainline
# make your changes
hg com -m "I fixed the bug"
hg push -r mainline   ## now others can pull it!
hg up -r sideproject
hg merge mainline
hg com -m "merge mainline bugfix into sideproject"

Done.

There are ways, by using the mq extension or exporting patches, that allow you edit the history to achieve similar results, but they all are simply trying to accomplish the above method after the fact.

A changeset carries with it all changes in it's ancestry. So you need to topologically separate the mainline change (revision 24) from your side project (revs through 23).

like image 52
Edward Avatar answered Aug 15 '26 08:08

Edward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!