0

I need help in understanding hg log --follow.

$ hg log --help
...
 -f --follow              follow changeset history, or file history across
                          copies and renames

When I specify -f, the log output includes all the commits. I expected it to return commits related to the file changed in the given revision. Is this the intended behaviour of the -f flag. If so, what is its use case?

/tmp:$ hg --version
Mercurial Distributed SCM (version 4.5.3)
/tmp:$ mkdir hg-f
/tmp:$ cd hg-f
/tmp/hg-f:$ hg init
/tmp/hg-f:$ touch file0
/tmp/hg-f:$ hg add file0
/tmp/hg-f:$ hg commit -m 'file0 added'
/tmp/hg-f:$ touch foobar
/tmp/hg-f:$ hg add foobar
/tmp/hg-f:$ hg commit -m 'added foobar'
/tmp/hg-f:$ hg mv foobar barfoo
/tmp/hg-f:$ hg commit -m 'moved foobar'
/tmp/hg-f:$ hg log -v -r 2
changeset:   2:492bd607810c
tag:         tip
user:        'notalex'
date:        Tue Apr 16 09:10:25 2019 +0530
files:       barfoo foobar
description:
moved foobar

/tmp/hg-f:$ hg log -v -f -r 2
changeset:   2:492bd607810c
tag:         tip
user:        'notalex'
date:        Tue Apr 16 09:10:25 2019 +0530
files:       barfoo foobar
description:
moved foobar

changeset:   1:adfd98042078
user:        'notalex'
date:        Tue Apr 16 09:10:14 2019 +0530
files:       foobar
description:
added foobar

changeset:   0:64e5211bd019
user:        'notalex'
date:        Tue Apr 16 09:09:53 2019 +0530
files:       file0
description:
file0 added
Alex
  • 1,618
  • 1
  • 17
  • 25
  • In your pasted example, can you clarify what parts of it were unexpected? – StayOnTarget Apr 16 '19 at 11:23
  • @DaveInCaz - I suppose, Alex expected **do not see** r0, which is unrelated to r2 in terms of affected files at all – Lazy Badger Apr 16 '19 at 11:43
  • @LazyBadger, thank you it was below the scroll and I didn't see that! – StayOnTarget Apr 16 '19 at 12:08
  • @Alex is this what you are looking for ? https://stackoverflow.com/questions/3459161/how-to-view-revision-history-for-mercurial-file – StayOnTarget Apr 16 '19 at 12:09
  • @DaveInCaz, my intention is to understand the **--follow** flag behaviour. Why does it exist if it is to return the entire log regardless? – Alex Apr 16 '19 at 14:52
  • I don't think anyone other than the people who created HG can answer a "why" question. Personally I use follow mainly for tracking renamed/moved files. You can also use it to track the history of a single file (as noted in the other question, linked above). – StayOnTarget Apr 16 '19 at 15:50
  • The linked question does not refer to **--follow** anywhere. I do not see that **-f** is used to follow the history of a single file, because in my above example; it is clearly not. – Alex Apr 17 '19 at 00:47
  • @Alex sorry, I misstated or badly garbled what I meant about the other question. I think what I meant was that follow is NOT needed for simple cases (no renames, etc.) – StayOnTarget Apr 17 '19 at 16:38

1 Answers1

0

You have to read docs more fully and carefully (I never used -f without filename, thus - read this related para first time too)

File history is shown without following rename or copy history of files. Use -f/--follow with a filename to follow history across renames and copies. --follow without a filename will only show ancestors of the starting revision.

0 is the ancestor of 2 in terms of DAG, OK. If you want to see and understand real purpose of -f, you have just compare output of (for your test-case)

hg log barfoo vs hg log -f barfoo

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110