Use "hg unshelve" like unstashing with Git
Asked Answered
C

2

6

When invoking hg unshelve --keep and I get a conflict, I need to resolve the conflict and then invoke hg unshelve --continue --keep again. Why is the last step necessary? And why I can't invoke hg unshelve --continue --keep directly without resolving the commit - to get out of the unshelving state?

c:\temp\hg test>hg st
M new.txt

c:\temp\hg test>hg commit -m "fjdjkfs"

c:\temp\hg test>hg unshelve --keep
unshelving change 'shelve'
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
merging new.txt
warning: conflicts during merge.
merging new.txt incomplete! (edit conflicts, then use 'hg resolve --mark')
unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')

c:\temp\hg test>hg st
M new.txt
? new.txt.orig

c:\temp\hg test>hg unshelve --keep --continue
abort: unresolved conflicts, can't continue
(see 'hg resolve', then 'hg unshelve --continue')

c:\temp\hg test>hg resolve --mark

c:\temp\hg test>hg unshelve --keep --continue
no changes needed to new.txt
unshelve of 'shelve' complete

c:\temp\hg test>hg st
warning: ignoring unknown working parent 11667b875a2d!
? new.txt.orig
Cobbler answered 7/4, 2015 at 17:12 Comment(0)
C
1

This seemed to be a problem with the Mercurial version I was using. With latest version 3.4 it works as expected.

Cobbler answered 9/5, 2015 at 10:49 Comment(0)
C
0

Why is the last step necessary?

Because it's possible that not all changes have been applied yet. The merge conflict may happen halfway through the unshelving operation. In this case, you need to pass control back to Mercurial to apply the remaining changes.

And why I can't invoke hg unshelve --continue --keep directly without resolving the commit - to get out of the unshelving state?

If you just want to get out of the unshelving state, and don't care about applying the changes correctly to your working directory, you should just do hg unshelve --abort. The --continue flag is for resuming the unshelve after fixing merge conflicts. Mercurial won't let you do that without resolving the conflicts because this would leave your working directory in a broken state.

See hg help unshelve for more information about these arguments.

Cloninger answered 4/5, 2015 at 14:32 Comment(4)
I don't understand your first argument. How Git or SVN can handle conflicts for all files? I don't understand your second argument either. I want to apply the shelve, but keep it - no matter whether I get conflicts or not. Unshelve should not care whether I solve the conflicts or not. It just leaves the repository in a broken ("unshelving") state because the Hg developers implemented it that way. IMHO this state is useless.Cobbler
This isn't a forum for arguments. I'm explaining how Mercurial actually works, not trying to justify it. If you want justifications, take it to the hg mailing lists or something.Cloninger
I can't get out of the unshelving state with keeping the unshelved changes using the suggested hg unshelve --abort. It just discards all partly unshelved changes.Cobbler
Yes, that's the point. It's for when you start unshelving and then realize that rebasing your changes is more trouble than it's worth. If you just want to quickly shoot yourself in the foot, write an alias for the resolve/continue combination.Cloninger

© 2022 - 2024 — McMap. All rights reserved.