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--reverseflag togit rev-listif you’d prefer chronological order: