简体   繁体   中英

Mercurial hg revert brought back old files

I've been working on a big project to update a large codebase for a client. They use Mercurial as their VCS.

As usual, I branched off their master branch at the start of the project.

As part of the project, I've deleted 250+ files in various parts of the codebase. These deletions (and other changes) have all been pushed back to the remote repository as the project has progressed.

Recently, I made a change that I decided I didn't want. Thinking I would just wind back to the previous commit, I typed in:

hg revert

Without checking for what had happened (stupid, I know), I committed and pushed.

I was horrified to see that a very large proportion (and seemingly random selection) of the files I have deleted over the project have been re-added to my branch. Looking through past commits where certain files had been deleted, those commits now contain the deleted files.

It's as if a chunk of my entire history has been altered, and in a way that I cannot understand.

How can such a simple command do something so crazy, and how can I undo these changes? I can't find a way to re-remove all those files other than manually picking through the codebase... surely this can't be the best solution?

Help very much appreciated!

From hg revert --help :

hg revert [OPTION]... [-r REV] [NAME]...

restore files to their checkout state

With no revision specified, revert the specified files or directories to the contents they had in the parent of the working directory . This restores the contents of files to an unmodified state and unschedules adds, removes, copies, and renames.

Because revert does not change the working directory parents, this will cause these files to appear modified.

So just based on the info in the question... it doesn't seem like reverting alone could have caused what is described.

Perhaps if there were other changes already in the working folder, or a merge was abandoned improperly, or the parent wasn't the most recent revision but some much earlier one, that could explain what happened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM