How to abandon all Mercurial changes that haven't been committed

落花浮王杯 提交于 2019-12-13 14:14:17

问题


How do you abandon all repository changes since the last commit in Mercurial?

I don't think that this is the revert command, because that will actually update the working directory to the last commit. I just want to undo changes in the repository (added files, removed files, etc).

But, I'm new with Mercurial, so I could be missing something.


回答1:


You do want revert. The two commands revert and update are complimentary. They both update the files in your working directory, but update also updates the parent revision (see hg parents) whereas revert doesn't. If your parent revision was tip, which it often is, then either would do in this case, but prefer revert.

Example:

ry4an@hail [~/hg/test] % hg stat
? newfile
? output.patch
? this
ry4an@hail [~/hg/test] % hg add newfile
ry4an@hail [~/hg/test] % hg stat
A newfile
? output.patch
? this
ry4an@hail [~/hg/test] % hg revert --all
forgetting newfile
ry4an@hail [~/hg/test] % hg stat
? newfile
? output.patch
? this



回答2:


This previous question may help: Mercurial — revert back to old version and continue from there

Particularly Martin's "cheat sheet" answer.




回答3:


Any changes to your local copy that have not been committed to the repository can be undone with the command:

hg update -C

That is, update clean.



来源:https://stackoverflow.com/questions/2773123/how-to-abandon-all-mercurial-changes-that-havent-been-committed

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