Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg: How do I revert (a single file) several commits back?

The closest answer is this one, and here's a line from it:

hg revert -r <oneRevBack> fileName

The last thing is to get <oneRevBack> other than using hash. I would dream of just typing <-1>.

like image 713
Dan Avatar asked Nov 05 '25 21:11

Dan


1 Answers

The hg syntax for "one rev back" is tip^, where tip is the latest revision and ^ means "parent". If your working directory is not at tip, use .^, where the dot means "current revision".

You can use hg revert -r tip~n file to revert to the nth ancestor of the tip (using the first parent if a commit has two parents). You can use -(n+1) only if there's only a single branch. -1 refers to the last revision, -2 the penultimate revision, and so forth, in order of revision numbering and not following the branch structure. (See hg help revsets for more details.)

like image 122
Peter Westlake Avatar answered Nov 07 '25 11:11

Peter Westlake