git-查找上次跨多个存储库修改文件的情况吗?

时间:2019-04-03 13:54:10

标签: git github

我在一家使用超过100个较小存储库构建单个应用程序的公司工作。

这些存储库中都有一个文件,例如ivy.xml,该文件显示了该项目对其他项目和第三方库的依赖关系。

我希望能够在我的开发机器上本地运行git命令,以找出所有存储库中ivy.xml文件的最后修改日期,并可能查看每个文件的日志语句和差异进行更改,即使我没有在本地将所有回购库全部签出,我也绝对不会这样做,因为其中有100多个!

如果从最近更改到最早的更改排序,那将是很棒的事情。

编辑:请注意,我愿意安装在用例中使用git或github的其他工具,以解决此问题而无需下载所有存储库。

2 个答案:

答案 0 :(得分:2)

您将不得不克隆存储库,但是,这应该可以工作:

repos="path1 path2 path3"
file="your/file"
branchToCheck="origin/master"
for repo in repos; do cd $repo; edit=$(git log -n 1 --pretty='format:%ci %s %h' "$branchToCheck" "$file"); echo $edit $repo ; cd - ;done | sort -r

它将输出如下内容:

2019-04-02 17:28:13 +0100 commit message COMMIT_HASH /path/to/repo1
2019-04-02 17:28:13 +0100 commit message COMMIT_HASH /path/to/repo2

按日期排序。

根据需要设置3个变量,并将第4行用作单行代码。

编辑:

这是我刚刚使用Github API进行的替代,它需要python3.6或更高版本:

https://gist.github.com/padawin/adf58c682d41b0596c969beb212e35c6

如果存储库不是公共的(需要提供身份验证),则需要更新。

答案 1 :(得分:1)

If you're using GitHub, you can use the commits method in the GitHub API to get the information you want.

Documentation: https://developer.github.com/v3/repos/commits/

The call you want is:

GET /repos/:owner/:repo/commits

For example, if you want to see the commits that modify LICENSE.md on https://github.com/clone95/Virgilio (picking a random repo trending on GitHub right now), this command will return that information:

curl 'https://api.github.com/repos/clone95/Virgilio/commits?path=LICENSE.md'

The most minimalist parsing you could do is to grep for "date":

curl 'https://api.github.com/repos/clone95/Virgilio/commits?path=LICENSE.md' | grep '"date"'
    "date": "2019-03-25T06:35:47Z"
    "date": "2019-03-25T06:35:47Z"
    "date": "2019-03-24T18:53:40Z"
    "date": "2019-03-24T18:53:40Z"

The results are actually a whole JSON record with lots of information. You could parse them carefully if you want, or just do a head -1 after the grep above to get the most recent commit's author date, or take the second line for the committer date. I leave this part up to you, as well as looping over your repos and sorting the results as you need.

Caveat: the author and committer dates are of course not the push date. You'd have to cross reference with the event log for that, if you really needed it: https://developer.github.com/v3/activity/events/