Mercurial (hg) equivalent of git reset (--mixed or --soft)

匿名 (未验证) 提交于 2019-12-03 02:13:02

问题:

what would be an equivalent mercurial command (or workflow) for

git reset --mixed HEAD^ 

or

git reset --soft  HEAD^ 

i.e. I want leave the working tree intact but get the repository back into the state it was before the last commit. Surprisingly I did not find anything useful on stackoverflow or with google.

Note that I cannot use

hg rollback 

as I've done some history rewriting using HistEdit after the last commit.

Added to clarify: After some rebasing and history editing I had ended up with A<--B<--C. Then I used HistEdit to squash B and C together, obtaining A<--C'. Now I want to split up the commit C' (I committed the wrong files in B). I figured the easiest way to do this was to get the repository back to state A (which technically never existed in the repository because of all the rebasing and history editing before hand) and the working tree to the state of C' and then doing two commits.

回答1:

The right way to replicate git reset --soft HEAD^ (undo the current commit but keep changes in the working copy) is:

hg strip --keep -r . 

-1 will only work if the commit you want to strip is the very last commit that entered the repository. . refers to the currently checked out commit, which is the closest equivalent Mercurial has to Git's HEAD.

Note that if . has descendants, those will get stripped away too. If you'd like to keep the commit around, then once you have the commit ID, you can instead:

hg update .^ hg revert --all -r <commit id> 

This will update to the commit's parent and then replace the files in the working copy with the versions at that commit.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!