开发者

Mercurial: Getting changed files from revision?

开发者 https://www.devze.com 2023-01-25 03:05 出处:网络
I can\'t get my head around how I can get only the files that were changed in my last revision, and not the complete repo, which i get by using Clone. This wouldbe super helpful to for instance, deplo

I can't get my head around how I can get only the files that were changed in my last revision, and not the complete repo, which i get by using Clone. This would be super helpful to for instance, deploy the last changed开发者_StackOverflow files.

What do I do?

Thanks


You cannot transfer just some files -- you must always have a full clone locally. So I suggest you make that once and then pull in changes incrementally.

You should then use hg status to show the names of files changes been revisions. You normally use hg status to see which files are changes compared to the working copy parent revision, but you can pass --rev to status to see changes between any two revisions!

So use

$ hg status --change tip

to see which files were changed in the tip changeset. Use

 $ hg pull
 $ hg status --rev .:tip

to see what files will be changed when you do a hg update after a pull. The update will take you from the current working directory parent, denoted by ., to the tip, assuming you are on the same named branch as tip. Otherwise hg update will take you to the tip-most changeset on your current branch.


You can use a template to hg log or hg tip to get all filenames:

hg tip --template '{files}'

or to get e.g. all files changed/added/modified by changeset 5:

 hg log -r5  --template '{files}'

You can read more about templates Mercurial: The Definitive Guide, Chapter 11. Customizing the output of Mercurial or short help with hg help templating`

If you want to do something to the files e.g grep through them:

hg tip --template '{files}' | xargs grep foo  

Careful this will break with filenames containing spaces!

To process all kinds of filenames something more complicated is needed (thanks to mg on #mercurial for the tip):

We need multiline styles for this suppose a file named zerosep contains:

changeset = "{files}"
file = "{file}\0"

Then you can use this to produce a \0 separated list of filenames and process it with xargs -0:

hg tip --style zerosep | xargs -0 grep foo

Information how this works can be found in: Listing files on multiple lines


Martin has the right way to get a list of what files have changed in a revision, and I've upvoted his answer, but just to expand on why your question is a little off:

In Mercurial every location has a full copy with all changes. If you're going to use Mercurial to deploy to your server then you have to clone everything to your server -- once. After that push/pull will move over only the (compressed) changesets that the server doesn't already have.

If you don't want to have everything that ever was on the server, then you need to use something other than mercurial for your deployment, perhaps something fed from the status commands Martin showed or a snapshot created from hg archive.

Personally, I'm okay with having full history on my servers, and just do a hg pull ; hg update on the server for each new deployment. It's tidy and efficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号