简体   繁体   English

GIT-获取提交消息和上次拉取的差异

[英]GIT - Get commit messages and diff from last pull

I have a project that contains GIT submodules. 我有一个包含GIT子模块的项目。 I'd like to gather the changes in that submodule into a text file and send that text file to a Jenkins email template. 我想将子模块中的更改收集到一个文本文件中,然后将该文本文件发送到Jenkins电子邮件模板。

Right now, I have this command, which gets me that changed files in that submodule: 现在,我有了以下命令,该命令使我更改了该子模块中的文件:

git diff origin/master --stat >> fullLog.txt

And the generated file looks like this 生成的文件如下所示

 test.cs             | 8 +++++++-
 test1.cs            | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)

Ideally I would like the commit messages that we're just pulled but looking at the git-log documentation I would have to know which commit to limit from. 理想情况下,我希望收到刚刚提交的提交消息,但查看git-log文档后,我必须知道要限制哪个提交。 Right now when I do git log -p I get every message since the start of the project. 现在,当我执行git log -p我会收到从项目开始以来的所有消息。

My desired end result would look something like this: 我想要的最终结果将如下所示:

Commit a2a4cd6a72892d7a6f0f6e2097d8bf13826a56c3 by jsmith
test-111: clears cache

Commit c58a86c8ebc7153d65c0bfdf0d8e5f92be571b9f by psmith
test-112: Changed setting

 test.cs             | 8 +++++++-
 test1.cs            | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)

If you know you just pulled AND the pull actually had new commits, then you can make use of the reflog to find out what the state of your HEAD was right before the pull, and use that as an argument to git log. 如果您知道自己刚刚被拉出,并且拉出实际上有新的提交,那么您可以利用reflog来找出拉出之前HEAD的状态,并将其用作git log的参数。 The state of HEAD before the last update to HEAD is HEAD@{1} , so this might work: 上次更新HEAD之前HEAD的状态为HEAD@{1} ,因此这可能起作用:

git log HEAD@{1}.. --stat

You can run git reflog to see the reflog itself. 您可以运行git reflog查看reflog本身。 Note that the reflog is not updated if a git pull did not pull in any new commits for the checked-out branch. 注意,如果git pull没有为检出的分支引入任何新的提交,则不会更新reflog。

I assume you're running this in a script, so a solution that would work regardless of whether there were changes pulled or not is to save the previous state of origin/master before pulling. 我假设您正在脚本中运行此脚本,因此无论是否进行了更改都可以使用的解决方案是在保存之前保存origin/master状态origin/master状态。

prev_master=`git rev-parse origin/master`
git pull
new_master=`git rev-parse origin/master`
if [[ $prev_master == $new_master ]]; then
   #nothing pulled
else
   git log $prev_master..$new_master --stat
fi

And if you want the file stats globally but the log commit by commit, you could use these two commands instead of the single git log line: 而且,如果要全局获取文件统计信息,但要通过提交提交日志,则可以使用以下两个命令,而不是单个git log行:

git log $prev_master..$new_master
git diff --stat $prev_master..$new_master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM