我如何通过一系列的提交到Git的日志? [英] How do I pass a range of commits to git log?

查看:88
本文介绍了我如何通过一系列的提交到Git的日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我放弃了,我是一个小白猛砸

  $ git的日志--no步行--oneline 6980e6ecede8e188f434f6da669c2297f28decfe 458567536c1f20498da033cb0e42da74439ef12e

打印:

  4585675 NNN bethDataFiles,allBethFiles属于游戏/游戏/ constants.py
6980e6e NNN bethDataFiles,allBethFiles属于游戏/游戏/ constants.py

  git的日志-g  -  pretty =格式为:%AI%H'| awk的'$ 0 GT =2016年4月13日与&&安培; $ 0℃=2016年4月15日'|切-d''-f 4 | AWK'一[$ 0] ++!| TR的'\\ n'''

我打印了一系列的提交:

  ba4ee4b099d23642e6cad56d9f41974f6e767781 1daaede0f4e11cae0e0bb00b9ebb43bba4f5671 ...

现在为什么地球上的管道此命令git的日志中:

  git的日志-g  -  pretty =格式为:%AI%H'| awk的'$ 0 GT =2016年4月13日与&&安培; $ 0℃=2016年4月15日'|切-d''-f 4 | AWK'一[$ 0] ++!| TR'\\ r \\ n'''| git的日志--format ='%H%S%AI'--no行走

只显示我的第一个承诺:

  ba4ee4b _load_active_plugins pre BAPI code  - 通过取代API games.py:2016年4月14日19点38分41秒+0200

  $的git --version
Git版本2.6.1.windows.1


解决方案

有与bash和Unix实用工具的一般形式:

  ... | ... | ... | xargs的CMD

的xargs 运行 CMD 不止一次在需要插入标准输入作为参数后,更多),或者:

  CMD $(... | ... | ...)

它运行的管道,然后提供它作为参数输出到 CMD

然而, git的日志你不需要这个,因为它接受 - 标准输入来得到它从标准输入读取修订版本ID。

我想,我们可以简化您的管道(顺便说一下,我并没有意识到AWK的一些版本知道如何直接比较日期;老年AWK没有):

  git的日志-g  -  pretty =格式为:%AI%H'| \\
    awk的'$ 0 GT =2016年4月13日与&&安培; $ 0℃=2016年4月15日'| \\
    切-d''-f 4 | AWK'一[$ 0] ++!| TR的'\\ n'''

我们希望修订为每行一个,所以没有必要在 TR 。我们也可以使用原始awk来检查的哈希标识的唯一性。所以:

  git的日志-g  -  pretty =格式为:%AI%H'| \\
    awk的'$ 0 GT =2016年4月13日与&&安培; $ 0℃=2016年4月15日与&&安培; !一个[$ 4] +'| \\
    git的日志--no-走--stdin

顺便说一句,这不仅是因为 git的日志-g 做了引用日志散步(这可能会产生重复的哈希值),我们需要关联数组 A 丢弃重复的哈希值。

Ok I give up, I am a Bash noob.

This:

$ git log --no-walk --oneline 6980e6ecede8e188f434f6da669c2297f28decfe 458567536c1f20498da033cb0e42da74439ef12e

prints:

4585675 NNN bethDataFiles, allBethFiles belong to game/game/constants.py
6980e6e NNN bethDataFiles, allBethFiles belong to game/game/constants.py

This:

git log -g --pretty=format:'%ai %H' | awk '$0 >= "2016-04-13" && $0 <= "2016-04-15"'| cut -d' ' -f 4 | awk '!a[$0]++' | tr '\n' ' '

prints me a range of commits:

ba4ee4b099d23642e6cad56d9f41974f6e767781 1daaede0f4e11cae0e0bb00b9ebb43bba4f5671 ...

Now why on earth piping this command to git log as in:

git log -g --pretty=format:'%ai %H' | awk '$0 >= "2016-04-13" && $0 <= "2016-04-15"'| cut -d' ' -f 4 | awk '!a[$0]++' | tr '\r\n' ' ' | git log --format='%h %s %ai' --no-walk

only shows me the first commit:

ba4ee4b _load_active_plugins pre BAPI code - superseded by games.py API: 2016-04-14 19:38:41 +0200

?

$ git --version
git version 2.6.1.windows.1

解决方案

There's a general form with bash and Unix utilities:

... | ... | ... | xargs cmd

(xargs runs cmd more than once as needed after inserting stdin as arguments), or:

cmd $(... | ... | ...)

which runs the pipeline, then provides its output as arguments to cmd.

However, with git log you don't need this as it accepts --stdin to get it to read revision IDs from standard input.

I think we can simplify your pipeline (incidentally, I did not realize some versions of awk know how to compare dates directly; older awk did not):

git log -g --pretty=format:'%ai %H' | \
    awk '$0 >= "2016-04-13" && $0 <= "2016-04-15"' | \
    cut -d' ' -f 4 | awk '!a[$0]++' | tr '\n' ' '

We want the revisions to be one per line so there's no need for the tr. We can also use the original awk to check the uniqueness of the hash ID. So:

git log -g --pretty=format:'%ai %H' | \
    awk '$0 >= "2016-04-13" && $0 <= "2016-04-15" && !a[$4]++' | \
    git log --no-walk --stdin

Incidentally, it's only because git log -g does a reflog walk (which may produce duplicate hashes) that we need the associative array a to discard repeat hashes.

这篇关于我如何通过一系列的提交到Git的日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆