相当于git reset(--mixed或--soft)的Mercurial(hg) [英] Mercurial (hg) equivalent of git reset (--mixed or --soft)

查看:85
本文介绍了相当于git reset(--mixed或--soft)的Mercurial(hg)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git reset --mixed HEAD^

git reset --soft  HEAD^

即我想保持工作树完整无缺,但要使存储库恢复到上一次提交之前的状态.令人惊讶的是,我在stackoverflow或Google上找不到任何有用的东西.

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.

请注意,我不能使用

hg rollback

因为我在最后一次提交后使用HistEdit进行了一些历史记录重写.

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

添加以进行澄清: 经过一些基础和历史编辑后,我最终得到了A< B< C".然后,我使用HistEdit将B和C一起压扁,得到A< C'.现在,我想拆分提交C'(我​​在B中提交了错误的文件).我认为最简单的方法是将存储库恢复到状态A(由于之前已经进行了所有重新定基和历史编辑,因此从技术上讲它不存在于存储库中),然后将工作树恢复为C'状态,然后执行两次提交.

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.

推荐答案

复制git reset --soft HEAD^的正确方法(撤消当前提交,但将更改保留在工作副本中)是

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仅在要剥离的提交是进入存储库的最后一次提交时才有效. .是指当前已签出的提交,这是Mercurial与Git的HEAD最接近的等效项.

-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.

请注意,如果.具有后代,则这些后代也会被剥夺.如果您希望保留提交,那么一旦获得提交ID,您就可以:

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.

这篇关于相当于git reset(--mixed或--soft)的Mercurial(hg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆