con-f-use
con-f-use

Reputation: 4028

How do I make a pull request for only one specific commit in Mercurial?

I have forked a Mercurial repository hosted on Bitbucket. I don't have write permissions for the original repository. I made several commits to my fork. Let's call them A, B, C and D, i.e. latest first:

Now I want to make pull request for all the changes in commit B exclusively, ignoring A, C and D. Is there a way to do this?

Upvotes: 0

Views: 324

Answers (1)

Pulkit Goyal
Pulkit Goyal

Reputation: 780

First of all let's understand how your graph looks like. Let's suppose the tip of your forked repo is x and it has linear history with no branching. So your history looks like this:

[1000's of commits] -> parent(parent(x)) -> parent(x) -> x

Now you made four commits namely A, B, C and D with A being the oldest one and D being the latest one. Now you graph looks something like this:

x -> A -> B -> C -> D

Note the history earlier than x is still intact, its not included above because its not required piece of information for what we are discussing.

Now you want to create a pull request containing only B changeset. That's not possible with current state because the main repo does not knows about A also which is parent of B. You can't have a child until it's parent/s is/are not there.

So if we want to just make a pull request of B changeset we need to rebase it on x.

rebase is an extension in Mercurial and you can turn it on by adding the following lines to your .hg/hgrc

[extensions]
rebase = 

Let's rebase once we have extension enabled.

hg rebase -s B -d x

This will result in:

x -> A
   \-> B -> C -> D

Now you can create a pull request because B's parent is x. You can also have more cleaner state of history by rebasing C to again A. It will result in two branches, one containing the changesets you want to push, other local changesets. Rebasing again looks like:

hg rebase -s C -d A

And the resulting state of history is:

x -> A -> C -> D
   \-> B

You can now easily create a pull request containing only B changeset.

Related Link:

Rebase Extension

Upvotes: 2

Related Questions