代码之家  ›  专栏  ›  技术社区  ›  linjunhalida

如何在Mercurial中获取文件创建/更新时间?

  •  5
  • linjunhalida  · 技术社区  · 15 年前

    我正在写我的博客系统(django),我的博客文件是由mercurial制作的,

    我想要获取文件的创建/更新时间,如何使用命令行或python来实现这一点?

    编辑:这是一个例子:

    $ SOME_COMMAND
    xxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
    xyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
    xxy.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
    yxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
    yyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
    
    3 回复  |  直到 15 年前
        1
  •  8
  •   Ry4an Brase    15 年前

    要获取文件的最新修改时间,请执行以下操作:

    hg log --template '{date}' -l 1 path/to/file
    

    要获得创建时间:

    hg log --template '{date}' -r 0:tip -l 1 README
    

    示例输出:

    $ hg log --template '{date}' -r 0:tip -l 1 README
    1115154970.028800
    
    $ hg log --template '{date}' -l 1 README
    1255462070.025200
    

    这些日期值是unix epoc秒,后跟一个点和一个时区偏移量。您可以使用中描述的各种过滤器对它们进行很好的格式化。 hg help templates 这样地:

    $ hg log --template '{date|rfc822date}' -l 1 README
    Tue, 13 Oct 2009 12:27:50 -0700
    
        2
  •  4
  •   Roger Pate    15 年前
    $ hg log -l1 --template "{date|isodate}\n" specific-file
    2010-08-18 21:00 -0400
    $ hg log -l1 --template "{date|isodate}\n"   # latest changeset
    2010-10-20 09:48 -0400
    

    ~/.hgrc,.hg/hgrc

    [alias]
    # last commit (ci being an alias for commit/check-in)
    lastci = log -l1 --template "{date|localdate|rfc822date}\n"
    # unless I'm misunderstanding, this will convert the date in the changeset to
    # your local timezone, then display as per rfc822
    

    $ hg lastci specific-file
    Wed, 18 Aug 2010 21:00:46 -0400
    $ hg lastci   # latest changeset
    Wed, 20 Oct 2010 09:48:29 -0400
    
        3
  •  1
  •   pyfunc    15 年前

    你可以用Hg日志

    temp $ mkdir test
    temp $ cd test
    test $ hg init .
    test $ cp ../a.py .
    test $ hg add a.py 
    test $ mate a.py 
    test $ hg commit -m "added file"
    test $ hg commit a.py -m "changed file"
    test $ hg log
    1[tip]   9c2bcca8ff10   2010-10-27 20:04 -0700   aranjan
      changed file
    
    0   d4f0137215c2   2010-10-27 20:04 -0700   aranjan
      added file
    
    test $ hg log a.py 
    1[tip]   9c2bcca8ff10   2010-10-27 20:04 -0700   aranjan
      changed file
    
    0   d4f0137215c2   2010-10-27 20:04 -0700   aranjan
      added file