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

1

4

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>.

Dexter answered 7/1, 2014 at 12:11 Comment(0)
K
7

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.)

Kettledrum answered 7/1, 2014 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.