Is it possible to undo an hg purge? - mercurial

I accidentally purged a few files I didn't mean to with "hg purge". Is there a way to undo this?

There is no way to undo a purge. It deletes files that weren't tracked by Mercurial, so Mercurial can't help you get them back.

Related

Equivalent of 'git rebase --skip' for 'hg rebase'

I'm doing a Mercurial rebase (induced by hg histedit) and I reach a conflict where I realize, actually, I should have dropped this patch. In git, I would have just done git rebase --skip. Is there an equivalent in Mercurial?
If you realize you should have dropped it, then the safe bet would be to do hg histedit --abort, then redo hg histedit and select drop for that changeset.
The only downside is losing progress on any other changeset conflicts already resolved in the same operation. To avoid that, there's hg histedit --edit-plan that allows changing the changeset to drop, and then use hg histedit --continue. But the current conflict still has to be resolved first, so for example hg resolve --all --mark could be done first. But I think this depends on the details of the current situation and gets much more complex and risky, and in most cases is probably not worth the trouble.

“Hg Rollback” would recover deleted files (removed via ‘hg remove’)?

I removed file “foo.cpp” using mercurial ‘hg remove foo.cpp’ from my repository and commit changes (say the revision of changeset is “22”), then I rollback the change by “hg rollback” and mercurial reported success “Repository tip rolled back to revision 21 (undo commit)”.
Does ‘hg rollback’ recover deleted files from the change-set being rolled back? Seems like it does not recover removed files, is this by design?
The rollback reverts the commit, not the remove. If you hg status, you will see the uncommitted removal of foo.cpp. If you do a clean update to the parent via hg update -C, foo.cpp will be restored.

Undo "discard" local changes after merge in TortoiseHg

I just lost a bunch of work because I accidentally clicked "discard" when I tried to merge in remote changes.
Can anyone recommend a way to recover my uncommitted local changes? :'(
Does Mercurial or TortoiseHg store a backup somewhere of the last deleted changes?
Was it through this window?
In which case, I'm afraid, no, there is not.
I believe this window calls the command hg update -r MY_BRANCH -C, where the -C flag denotes there will be no backups.
As an aside, if it was a different way, you'd want to be looking for .orig files, which would be the format of the backup.

How to reinstate most recent commit in Mercurial?

I've searched the docs of Mercurial and still am confused. What I'm wanting to do is just reinstate the last commit I made i.e. I want my project to go back to being exactly the same as it was when I made the last commit. I see hg revert, rollback, etc. and still am not understanding which is correct for this situation. Which should I use?
The hg rollback command is used to undo the last action that modified Mercurial's internal store, usually a pull or commit. So, if you want to undo your last commit hg rollback will work.
But it sounds like you want to undo all your uncommitted changes. You have two options. The hg revert --all command will undo all uncommitted changes. Each changed file is saved/backed-up with a .orig extension before being reverted.
If you don't need to preserve your changes in .orig files, run hg update -C. This clears out all uncomitted changes, without preserving anything.
If you have commited changesets and wish to remove them, I like the strip extension, strip extension. With it, you can remove explicit changesets from your history.
However, strip is an unforgiving command, i.e. if you get it wrong there is no retrieval unless you have a backup of the repo. You might prefer the prune command which comes with the evolve extension. Using prune, you can mark changesets as obsolete and they will no longer normally be visible in logs or tortoise. [You can make them visible by adding --hidden on an hg log command line, or in tortoise by enabling the Filter toolbar (from the view menu) and selecting 'Show/Hide hidden changesets'.]

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

This question already has answers here:
Is there any way to delete local commits in Mercurial?
(10 answers)
Closed 8 years ago.
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.
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.
hg rollback, and you can find more in the Chapter 9. Finding and fixing mistakes of the Mercurial: The Definitive Guide
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.