Mercurial: Revert a single hunk

本秂侑毒 提交于 2019-12-20 17:38:36

问题


How do I revert a single hunk in Mercurial, similar to the way it's done in darcs, i.e. it asks me for each hunk and file whether I want to revert it? Is it possible using TortoiseHg?

Thanks


回答1:


The record extension is inspired by darcs record. It will allow you to add only specific hunks to the next commit, i.e., the opposite of what you want. But you could add all hunks except the one you want to revert and then do a hg revert to revert it. A little backwards, I know... :-)

You could also do hg diff > patch; hg revert, edit patch to delete the hunk and do hg import --no-commit to reappy the patch. That is likely faster, but requires you to manually edit the patch. I've had great success with the Emacs diff-mode, but since you ask about TortoiseHg you might not want to use Emacs.




回答2:


Actually mercurial refers to "chunks", at least in the Shelve tool. Which brings me to favorite way to revert them (and favorite features of TortoiseHg).

Just move the chunks you want to revert onto a shelf you create solely with the intention to delete. This works really well as long as the chunks are identified as you need them to be. If not, you've got no choice but to do something manually.

If you use TortoiseHg Workbench or VisualHg, it is very easy to get to the Shelve tool: there is a button next to the diff mode toggle buttons. If you are not familiar with shelves, do yourself a favor and start using it. It has saved me much aggravation when I've forgotton to commit early, or decided to leave out experimental code from a commit.




回答3:


For reversing a changeset on a single file try:

hg diff -c | patch -R

That will reverse the changeset introduced by that revision on that filename. Now if the same darcs/git style cherry-picking behavior could be included in that somehow I would be very happy.



来源:https://stackoverflow.com/questions/876763/mercurial-revert-a-single-hunk

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