2

Is there a way to graft a commit onto somewhere other than the current revision?

The documentation makes it sound like there isn't:

hg graft [OPTION]... [-r REV]... REV...

copy commits from a different location

And I don't see any parameters that can be passed to hg graft to do so. I'm surprised though that hg rebase allows this with the -d flag, but hg graft doesn't. Just like how sometimes I want to rebase a branch to somewhere other than the current revision, sometimes I want to graft a branch to somewhere other than the current revision.

Community
  • 1
  • 1
Mark
  • 1,746
  • 2
  • 18
  • 19

2 Answers2

1

You can use the rebase extension to achieve this. Do hg rebase -r <rev> -d <dest> --keep to rebase the onto while keeping the old rev.

Pulkit Goyal
  • 780
  • 4
  • 20
  • Thanks! This looks great. One bummer is apparently bookmarks will still be moved during the rebase, but that can be fixed pretty quickly. – Mark Apr 15 '19 at 05:41
  • @Mark I no longer understand your question, which seemed to state you wanted something other than rebase and that you already knew rebase could do this. – StayOnTarget Apr 15 '19 at 10:25
  • @DaveInCaz no, I didn't realize rebase could do this until your answer. After I read your answer I checked out the man page for rebase and found out about the bookmarks. – Mark Apr 16 '19 at 06:35
  • @Mark got it! Thanks – StayOnTarget Apr 16 '19 at 09:13
1

Fundamentally the answer is "no", but you can still get the desired effect.

The help text for graft says "copy changes from other branches onto the current branch " which implies that if you first update to the destination changeset, you can get the result you want.

Presumably you want to use graft to make an actual copy, vs rebase which would "move" the changeset. So this will get that result although it requires several steps.

To summarize:

hg up <destination revision>
hg graft <source revision>
hg up tip
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • Thanks, indeed this would achieve the desired ultimate effect. However I'm really interested in a solution that won't make me `hg up` anywhere. This is for cases where my current checkout is far from the destination and I would waste time updating to it (and potentially back, if I just want to stay where I am). – Mark Apr 15 '19 at 05:40
  • 1
    @Mark yeah those kinds of updates can take a while, that's for sure! – StayOnTarget Apr 15 '19 at 10:26