简体   繁体   中英

How can I undo a hg push

Basically what has happened is this:

I moved a bunch of files from one directory to another directory. I then committed my change and pushed it. Then I notice that my "move" actually wasn't a move but Mercurial, I guess, actually copied the files I wanted to move and pasted them in the new directory and then deleted the original files.

The unintended result of this is that all the history is lost since it is no longer the old files but new ones.

So what I would like to know is how do I revert/rollback/backout this change?

I have read about all three ways but I'm still not sure which is the best way to approach this. I just want to backout my push so that I can move the files correctly without losing all the history.

You can't directly "undo" a push but there are ways to essentially negate its effects.

Option 1: The most straightforward option is if you have full control over all clones which have received the pushed commit which was in error. If so, use hg strip on all of them to remove the bad commit(s).

Option 2: If you cannot do that, you could delete the incorrectly added files and revert the deletion of the original files ( example ), and then just redo the operation as you originally intended.

Option 3: Update back to the commit prior to the bad one. Then use hg move to correctly relocate the files, and commit that which will create a new head (since you were working off a revision older than the current tip). Then merge this new head with the tip. That should cause the history to be retained.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM