git log --pretty和文件列表? [英] git log --pretty with list of files?

查看:1008
本文介绍了git log --pretty和文件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用'git log --pretty = tformat'来创建xml文件日志。然而,我有问题得到每个提交的文件列表。



例如:
我使用此命令

  $ echo'<?xml version =1.0?>'> out.xml 
$ echo'< git>'>> out.xml
$ git log --pretty = tformat:'< commit>%n< h1>%s< / h1>%n< / commit>'--name-only>> out.xml
$ echo'< / git>'>> out.xml

输出:

 <?xml version =1.0?> 
< git>
< commit>
< h1>委托1< / h1>
< / commit>
< commit>
< h1>委托2< / h1>
< / commit>
< commit>
< h1>提交3< / h1>
< / commit>
< / git>

我想将标记添加到文件列表的提交标记中,这样我的最终输出看起来像这

 <?xml version =1.0?> 
< git>
< commit>
< h1>委托1< / h1>
< list> file1< / list>
< / commit>
< commit>
< h1>委托2< / h1>
< list> file2< / list>
< / commit>
< commit>
< h1>提交3< / h1>
< list> file3< / list>
< / commit>
< / git>

我试过--name-only它会列出文件,但不能格式化输出。

解决方案

这可能不是什么你正在寻找,但脚本很容易。以下是一个实现,效率低下但功能强大。小心运行它:它将在您的整个历史上运行。将第二行更改为 revlist = $(git rev-list -10 HEAD)以查看最近10次提交时的工作情况。它也假设你想要在文件底部进行较早的提交,按照上面的例子。如果你喜欢时间顺序,请在 git rev-list 中添加一个 - reverse 标志:



$ $ p $ $ $ $ $ $




















$ b $ <?xml version =1.0?>'
echo'< git>'
for $ revlist
do
files = $(git log -1 --pretty =format:--name-only $ rev)
echo'< commit> \\\
< h1> \c'
echo$(git log -1 - -pretty =%s$ rev)\c
echo $< / h1>'
for $ files
do
echo< list>
完成
echo'< / commit>'
完成
echo'< / git>'
)> out.xml


I am trying to use 'git log --pretty=tformat' to create xml file log. However I have problem getting the list of file for each commit.

for example: I use this command

$echo '<?xml version="1.0"?>' > out.xml
$echo '<git>' >> out.xml
$git log   --pretty=tformat:'    <commit>%n        <h1>%s</h1>%n    </commit>'  --name-only  >> out.xml
$echo '</git>'>> out.xml

the output:

    <?xml version="1.0"?>
<git>
    <commit>
        <h1>Commit 1</h1>
    </commit>
    <commit>
        <h1>Commit 2</h1>
    </commit>
    <commit>
        <h1>Commit 3</h1>
    </commit>
</git>

I want to add tag in side the commit tag with the list of files so my final output look like this

    <?xml version="1.0"?>
    <git>
        <commit>
            <h1>Commit 1</h1>
            <list>file1</list>
        </commit>
        <commit>
            <h1>Commit 2</h1>
            <list>file2</list>
        </commit>
        <commit>
            <h1>Commit 3</h1>
            <list>file3</list>
        </commit>
    </git>  

I did try --name-only it will list the file but cannot format the output.

Any help would be much appreciated.

解决方案

This might not be what you're looking for, but it's easy to script. The following is one implementation, inefficient but functional. Careful running it: It will operate on your entire history. Change the second line to revlist=$(git rev-list -10 HEAD) to see it work on just the last 10 commits. It also assumes you want older commits at the bottom of the file, per your example above. Add a --reverse flag to git rev-list if you'd prefer chronological order:

#!/bin/sh
revlist=$(git rev-list HEAD)
(
    echo '<?xml version="1.0"?>'
    echo '<git>'
    for rev in $revlist
    do
            files=$(git log -1 --pretty="format:" --name-only $rev)
            echo '    <commit>\n        <h1>\c'
            echo "$(git log -1 --pretty="%s" $rev)\c"
            echo '</h1>'
            for file in $files
            do
                    echo "        <list>$file</list>"
            done
            echo '    </commit>'
    done
    echo '</git>'
) > out.xml

这篇关于git log --pretty和文件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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