当前位置: 动力学知识库 > 问答 > 编程问答 >

Mercurial: restore files

问题描述:

I'd like to restore a file that has been deleted in some commit, and restore it under a different name, so that it shares the history. In subversion, I'd do

svn cp [email protected] dest

i.e. use peg revisions. What's the equivalent in Mercurial?

网友答案:

I don't think Mercurial has a built-in way to do this. But I think you can get the same effect via:

hg up -C REV # Update to revision containing a copy of the file
<modify the file in question>
hg commit  # Create second head based on old revision
hg merge # Merge two heads into one
# Note: make sure to choose to have the file exist
hg commit
hg mv MYFILE MYNEWNAME

This will have the file keep all its old history, as best Mercurial can track it.

网友答案:

Wouldn't just (if you "hg remove"d src in REV+1):

hg revert -rREV src
hg status
A src
hg rename src dest
hg commit -m"restored src and renamed it to dest"

work?

edited: I just tested it and it seems to be ok. Actually no "hg add" is necessary for src as revert is taking care of this. However if you do just one commit instead of two (like in the code above), hg will give a warning:

src has not been committed yet, so no copy data will be stored for dest.

Hope it'll help.

分享给朋友:
您可能感兴趣的文章:
随机阅读: