Search code examples
mercurialmercurial-queue

how do I push most recent commit in HG


I have done some local commits.

But I want to push the most recent ones like 4977 and 4978 excluding the previous ones.

4948 local commit 1 is the ancestor of all commits

Can some one tell how do we do that in HG

4978 local commit 4
  |
  |
  |
4977 local commit 3
  |
  |
  |
4976 local commit 2
  |
  |
  |
4948  local commit 1

Solution

  • Mercurial repositories are intended to have immutable histories, so out of the box this is not possible. However, there are workarounds for this.

    Possibly the easiest way to achieve this would be with the histedit extension. You would need to enable it by modifying your .hgrc (or mercurial.ini) with the following

    [extensions]
    histedit = 
    

    Then you can run the histedit subcommand from the command line and tell it to look back as far as the changeset you're concerned about...

    hg histedit 4948
    

    This will pop up a text editor with the word pick next to each changeset. Change pick to drop for the changeset you don't want any more, save, and exit, and the problem changeset will be gone.

    Note that this will remove the changeset from your local repo, in addition to prevent it being pushed to the remote!