Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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_Python 3.x_Git_Gitpython - Fatal编程技术网

Python 如何获取git存储库中特定文件的特定行上的所有更改?

Python 如何获取git存储库中特定文件的特定行上的所有更改?,python,python-3.x,git,gitpython,Python,Python 3.x,Git,Gitpython,我们有一个已经使用多年的git存储库。比如说,这是一个Java-maven项目。该项目有pom.xml文件,其中包含以下重要信息 <model_location>path/to/file/model_version</model_location> 代码显示以下结果 afdb36153a53bc45eff52c319a9541498e1c3ce1 committer-1 2020-01-30 09:57:01 e85ca97121384fb34b0fdc1fa04

我们有一个已经使用多年的git存储库。比如说,这是一个Java-maven项目。该项目有
pom.xml
文件,其中包含以下重要信息

<model_location>path/to/file/model_version</model_location>
代码显示以下结果

afdb36153a53bc45eff52c319a9541498e1c3ce1    committer-1 2020-01-30 09:57:01
e85ca97121384fb34b0fdc1fa04cf78b6c1cd109    committer-1 2020-01-28 13:45:29
61bbf5d706b9dd2caa7b75e0374946ec1b96994c    committer-2 2020-01-23 17:44:20
...
c10ead963802053147488b93626ca0b9aab643b1    committer-3 2015-01-06 09:04:33
cf74128281e9374cca8e88a0e23e52f55e37f109    committer-3 2014-12-05 15:01:24

我得到了一个提交id列表,但我不知道如何读取特定提交id的
pom.xml
中的
model\u location
标记

其目的是了解在特定时期使用的模型。例如,在2014-12-05 15:01:24和2015-01-06 09:04:33之间使用了
型号3.14版
,并在型号中检查了
committer-3

如果你能告诉我,我将不胜感激。我写了另一个脚本,它与svn做同样的事情,但我不熟悉git


谢谢,

对不起,我的问题太仓促了。我找到了解决办法

        res = repo.git.show(f"{hexsha}:{path}/{os.path.basename(pom_xml_path)}")
        for line in res.split("\n"):
            match = re.match(regex, line)
            if match:
                model_location = match.group(1)
                model_name = os.path.basename(model_location)
                print(f"{hexsha}\t{committer_name}\t{model_name}\t{timestamp}")
        res = repo.git.show(f"{hexsha}:{path}/{os.path.basename(pom_xml_path)}")
        for line in res.split("\n"):
            match = re.match(regex, line)
            if match:
                model_location = match.group(1)
                model_name = os.path.basename(model_location)
                print(f"{hexsha}\t{committer_name}\t{model_name}\t{timestamp}")