Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在GIT中检查上次编辑的时间?_Python_Git - Fatal编程技术网

Python 如何在GIT中检查上次编辑的时间?

Python 如何在GIT中检查上次编辑的时间?,python,git,Python,Git,我在一本书中找到了这个代码。正如上面所说的,每次代码更新时,它可能会给出一些特定的时间戳。但正如我所注意到的,它只是给出了最后一次提交的时间。有没有一种方法可以获得每次代码更新的当前时间而不进行修改 import subprocess from datetime import datetime def get_git_changeset(absolute_path): repo_dir = absolute_path git_show = subprocess.Popen(

我在一本书中找到了这个代码。正如上面所说的,每次代码更新时,它可能会给出一些特定的时间戳。但正如我所注意到的,它只是给出了最后一次提交的时间。有没有一种方法可以获得每次代码更新的当前时间而不进行修改

import subprocess
from datetime import datetime


def get_git_changeset(absolute_path):
    repo_dir = absolute_path
    git_show = subprocess.Popen(
        'git show --pretty=format:%ct --quiet HEAD',
        stdout=subprocess.PIPE, stderr=subprocess.PIPE,
        shell=True, cwd=repo_dir, universal_newlines=True,
    )
    timestamp = git_show.communicate()[0].partition('\n')[0]
    try:
        timestamp = \
            datetime.utcfromtimestamp(int(timestamp))
    except ValueError:
        return ""
    changeset = timestamp.strftime('%Y%m%d%H%M%S')
    return changeset
更新:对于以某种方式登录此页面的用户-工作代码是将前3行替换为以下内容:

timestamp = max(map(lambda x: os.path.getmtime(x[0]), os.walk(absolute_path)))

您可以查看目录中文件的
mtime
(修改时间)以查看其是否已更改。
git
只关心提交,而不关心提交edits@Chiefirgit确实检查差异(这决定了git diff中显示的内容),但它并不关心这些更改是在什么时候进行的(它没有记录下来)。@r谢谢你给我的
mtime
的建议,这对我很有用。如果你想回答,我会接受。很好,我很高兴能帮上忙。代表没那么重要