How to uncommit in mercurial for my last commit(not yet pushed)

32,301

Solution 1

Assuming you haven't performed any other transactions on your repository since you committed the files, I think you could do this as a 2 stage process:

hg rollback
hg commit filec filed

hg rollback should remove the commit that you have just made, but leave the files as changed. Then hg commit filec filed should commit the files named filec & filed. Obviously you should replace these file names with the names of your actual files.

It's probably worth mentioning that you should be careful with hg rollback - it alters the history, so it is possible to lose data with it if used incorrectly.

Solution 2

hg rollback, and you can find more in the Chapter 9. Finding and fixing mistakes of the Mercurial: The Definitive Guide

Solution 3

In mercurial you can use the backout command, which creates a changeset that is the opposite of the changeset you want to backed out. Then this changeset is committed. The only thing you need to do after that is a merge.

You can backout any changeset, but it's not recommended to backout a merge changeset.

A detailed explanation of the command with an example can be found here.

Share:
32,301
skg
Author by

skg

Updated on June 17, 2020

Comments

  • skg
    skg about 4 years

    I have situation like this:

    I have commited files a,b,c,d.Now i found that by mistake i commited files a and b; so before pushing these changes, i want to do uncommit files a and b so that i can push only c and d.Can someone tell me how to do that by using mercurial commands.

    Here uncommit means that i dunt want to use "hg out -p" and after that looking change set and do things manually.