How can I extract all changed files of a changeset in Mercurial?
Asked Answered
J

4

8

Until recently we have been using SVN for all projects of our web studio, and there is a very convenient feature present in several clients like Subversive and TortoiseSVN that can extract all files that have been changed in a certain revision.

Is there a way to do it in Mercurial? I don't care if it's done via a GUI or a command line, it's just very convenient to have a set of files that have been changed in a certain changeset.

P.S. I must have put it wrong the first time. I need more than just a list of files, it would be great to have all the files exported to some other folder.

Judah answered 18/12, 2009 at 8:53 Comment(1)
Do you mean the file name or content or diff of the files?Cella
C
11

Building on Jerome's answer this will get you the copies of the files that changed in revision 4:

hg archive --type files --rev 4 -I $(hg log -r 4 --template {files} | sed 's/ / -I /g') ~/changedfiles

That puts all the files that changed into revision four into a newly created directory named changedfiles in your homedir.

If you change it to:

hg archive --type zip --rev 4 -I $(hg log -r 4 --template {files} | sed 's/ / -I /g') ~/changedfiles.zip

then they show up in a zip archive.

It's worth noting that that only works if you have no spaces in filenames. If you made that blunder then we'll need to use hg status --print0 -r revision -r parent-of-revision instead, but hopefully that's not necessary.

Note also that the revision number, '4' in our example, shows up twice. The whole thing could very easily be wrapped in a shell script, and that would be parameterized so you don't have to remember to change it in both places.

Corbeil answered 18/12, 2009 at 19:41 Comment(0)
E
7

This gives you the list of modified files in revision 4:

hg log -r 4 --template {files}

Update: If you'd like to have one file per line, you may use the style described in Hg book.

Eliezer answered 18/12, 2009 at 9:36 Comment(0)
A
1

Depending on your ned, there are two command:

  1. To get the changes associated with a particular revision, you can use hg export:

    hg export -r 23
    

This will generate a diff of all the changes (actually a formatted patch, ready to be applied)

  1. To get the name all the files that were affected, you can use hg log:

    hg log -r 23 -v
    

This will print the meta-info for the revision, along with the names of the files that were affected.

Amaras answered 18/12, 2009 at 9:20 Comment(3)
you could also of course hg diff -r rev -r rev-1 which would be the same as the diff part of exportAndreeandrei
@jk, hg export is better than hg diff, as it eliminates the step of finding the parent changeset, which isn't always decremental (e.g. the numberings get messed up with merges and such).Amaras
@notnoop, you can use hg diff -c for that :)Crammer
M
0

This command outputs names of all changed files in a specified revision:

hg export revision_num | grep ^diff | cut -f 6 -d ' '
Masto answered 18/12, 2009 at 9:14 Comment(1)
That's almost what I need! I only need to somehow pipe the result to cp and copy all files to some separate folder. Thanks!Boswall

© 2022 - 2024 — McMap. All rights reserved.