Mercurial: Getting changed files from revision?

岁酱吖の 提交于 2019-12-21 21:28:59

问题


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

What do I do?

Thanks


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4172819/mercurial-getting-changed-files-from-revision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!