104

How can you determine all the files that changed in a given changeset?

I'm not looking for a diff in this case, just a list of add/remove/modifications.

hg log -vprX does a list of diffs but I just want the files.

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • Possible duplicate of [Examining a single changeset in Mercurial](https://stackoverflow.com/questions/2550721/examining-a-single-changeset-in-mercurial) – Michał Wróbel Mar 08 '19 at 15:40

7 Answers7

156

If you want to list only files that have changed then you should be using "status command" The following will list the changes to files in revision REV

hg status --change REV
pyfunc
  • 65,343
  • 15
  • 148
  • 136
20

Current Committed Revision

hg status --change .

. is shorthand for the current rev, just like @HEAD in Git

Current Uncommitted Revision

hg status

Arbitrary Committed Revision

hg status --change REV_ID
Gibolt
  • 42,564
  • 15
  • 187
  • 127
16

Just remove p from your hg log -vpr will show the list of files. -p means show patch. You can also use a template to format the output to your taste.

Geoffrey Zheng
  • 6,562
  • 2
  • 38
  • 47
  • 3
    I think you will need the following template: --template 'files: {files}\n' – Ton Plomp Sep 26 '10 at 08:16
  • 1
    I believe the {files} is part of the -v flag default template – eskhool Oct 01 '16 at 18:45
  • 2
    hg log -r . --template '{join(files, "\n")}' to newline separate the files – Foxichu Nov 15 '16 at 11:53
  • 1
    @Foxichu comment worked for me, but was kinda hacky. actually the upper answer - `hg status --change .` worked better and gave a file action prefix (A\M\D etc) and better relative path – zaxy78 Mar 26 '19 at 13:15
15

I know the question is for a single changeset, but if you'd like to get all the files modified for a range of changesets, you can do

hg status --rev 1 --rev 10 -m
Nick DeVore
  • 9,748
  • 3
  • 39
  • 41
  • 2
    Terrible bad. Files, modified in range is `hg log -r BEGIN:END --template "{files}\n"` as @geoffrey-zheng and @ton wrote **two years ago!!!** – Lazy Badger Oct 31 '12 at 21:03
  • Sorry about that. Assumed their answer was for the single changeset. – Nick DeVore Nov 01 '12 at 15:16
  • 1
    In my opinion this answer is not that terrible. `hg status --rev BEGIN --rev END` is: 1. much easier to remember than `hg log -r BEGIN:END --template "{files}\n"`; 2. it prints the files in separate lines without using `sed` (@Eric Lawler) or `join()` (@Foxichu); 3. without the `-m` flag, it displays not only modified, but also added and removed files (the nice standard coloring applies here too); 4. there are `-a` and `-r` flags which allow different filtering; 5. if one doesn't want the status prefix, there's `-n` option, which suppresses it. – Michał Wróbel Jan 26 '18 at 16:24
2

Found this question through Googling for a similar concept. To show all files that changed through a range of changesets, it's as easy as:

hg log -r [start rev]:[end rev] --template "{file_mods}{file_adds}\n" | sed -e 's/ /\n/g' | sort -d | uniq
  1. hg log -r [start rev]:[end rev] --template "{file_mods}{file_adds}\n" will show you a list of each file changed or added in each changeset, from [start rev] to [end rev], with each changeset's files on a new line. Swap {file_mods}{file_adds} with {files} to show all files modified, added, or removed.
  2. sed -e 's/ /\n/g' will split all the files to show on separate lines and
  3. sort will, er, sort the list for you so we can filter the list with uniq
  4. uniq will filter the list to remove duplicates—files that changed in more than one revision.
Eric L.
  • 3,232
  • 2
  • 22
  • 20
  • This solution glues together the last modified with the first added file. Also, it doesn't properly deal with spaces in filenames. A `--template`-based solution without these shortcomings could be constructed using `join()` as suggested by @Foxichu. – Michał Wróbel Jan 26 '18 at 16:59
1

I know this question is an old question and I'm surprised nobody just offered modified code form OP. I got a list of modified/added/removed files (not labeled which is which though) by just running hg log -v. Or what I actually needed hg log -v -l5 to see files that have been modified/added/removed in the last 5 commits (including the ones that I didn't push yet to the repo).

Đorđe Relić
  • 418
  • 4
  • 13
-2

If you're like most shops, you use a ticketing system to track changes. If you know the ticket number and want to find all the commits associated with that ticket (assuming you include the ticket number in the commit message), you can use:

hg log -k TICKET_NUMBER

This does display the all the revisions associated with the ticket. However, it does not list the files. You could do use one of the answers above to then get the list of files associated with the revisions.

To make it simpler though, combining the info from the previous answers, you could do the following to search for commits, including files changed:

hg log -vk TICKET_NUMBER
  • This is related to the question. The poster asked how to get files in a changeset. Changesets are often related to tickets. My solution shows how to get files related to the changesets associated to a ticket. – iDimensionz Jan 26 '18 at 21:50