【问题标题】:Git log output log fileGit日志输出日志文件
【发布时间】:2012-04-21 05:56:24
【问题描述】:

我正在完成一项大学课程的作业,并且我正在使用 Git 作为该作业的版本控制。我一直在做的游戏已经完成。不过,我想连同手一起提交 Git 日志,有效地显示我在处理它期间的进度。

我试过这个:

git log --stat > log.log

但它或多或少只是给了我非常难以理解的东西。什么是命令,以便我可以得到一个很好的格式?

【问题讨论】:

  • 您希望输出的重点是什么?提交消息?分支?日期?文件?变化?
  • 你说的“非常不可读的东西”是什么意思?以什么方式?

标签: git logging


【解决方案1】:

我建议使用与默认格式不同的格式。我通常的选择是带有图表的摘要,但通常单独使用一行摘要就可以了。

选项 1: 带图表的单行摘要

git log --pretty=format:'%h : %s' --graph > log.log

结果:

* 2d3acf9 : ignore errors from SIGCHLD on trap
*   5e3ee11 : Merge branch 'master' of git://github.com/dustin/grit
|\
| * 420eac9 : Added a method for getting the current branch.
* | 30e367c : timeout code and tests
* | 5a09431 : add timeout protection to grit
* | e1193f8 : support for heads with slashes in them
|/
* d6016bc : require time for xmlschema

选项 2: 没有图表的单行摘要

git log --pretty=format:'%h was %an, %ar, message: %s' > log.log

结果:

a6b444f was Scott Chacon, 5 days ago, message: dammit, this is the second time this has re
49d77f7 was Scott Chacon, 8 days ago, message: modified index to create refs/heads if it i
9764edd was Hans Engel, 11 days ago, message: Add diff-lcs dependency
e1ba1e3 was Hans Engel, 11 days ago, message: Add dependency for Open4
0f87b4d was Scott Chacon, 12 days ago, message: merged recent changes

您可以在文档here 中找到更多格式选项。

【讨论】:

  • 我正在使用 '--' 将路径与修订分开
  • 可以在git-scm.com/docs/git-log 找到格式占位符。搜索子标题“漂亮的格式”
  • 仅供参考:我知道这个答案很旧,但“文档”链接已损坏。我当然不会像其他人对我所做的那样:在 3 年、4 年或 5 年以上之后投票否决我的答案,因为链接稍后会变坏。我已经提交了指向 git-scm.com (git-scm.com/docs/pretty-formats) 的编辑,仅供参考。
  • 无效的对象名称 %h
【解决方案2】:
git log --oneline --decorate > log.txt

【讨论】:

    【解决方案3】:

    试试这行

    git log > log.txt

    【讨论】:

    • 这是我所需要的基本答案。
    • git log 单独会在控制台上显示标签和分支(所有分支,包括远程分支)。但是, git log > log.txt 不会有那些标签/分支信息。我真的很想知道如何使它们相同(即使用标签/分支信息获取输出)
    猜你喜欢
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    相关资源
    最近更新 更多