Question

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
Was it helpful?

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!

OTHER TIPS

You cannot push a commit with out pushing all the ancestor commits as well. However, you can "fold"/"collapse"/"squash" commits together to get rid of the ancestor commits you don't like. You use the standard histedit extension for this.

Simply run

$ histedit 4948

and you will see an editor open up. That edit contains a file that will serve as the instructions for histedit. By default all changesets are left unchanged, but you can change the keyword at the beginning of the lines to change this. Also, you can reorder the lines to reorder the corresponding commits.

Changing the keyword in the beginning of a line to fold will tell histedit to combine the commit with the previous commit. That way you can change your history to

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

and thus "fold" the changes you made in your local commit 2 into local commit 3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top