I have a git repository, I can see all the commits in a particular branch using git log branch-name. But I want to print the commit message, author and date of all commits with respect to a particular branch on an HTML page. Is there any solution for this?
How can I use jgit for this?

有帮助吗?

解决方案

I don't know jgit, but in normal git you do that with the pretty option as

git log --pretty="%ci %an %s" branch-name

Where %ci is the date (ISO), %an is the commiter and %s is the subject.

EDIT

You can find more info in the log documentation, pretty format section : https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_pretty_formats

其他提示

git log --pretty=oneline commit1...commit2 > file

You will need to walk every commit on the branch and wrap the output with the appropriate html tags. Now I understand you want to do it from jgit, so I'll provide an outline of how one would do it in a shell, and you will have to similarly invoke the rev-list functionality of jgit:

#!/bin/sh

echo "<table style=\"width:300px\">"
for commit in $(git rev-list <your branch>); do
  git log --format="<tr><td>%cr</td><td>%an</td><td>%s</td></tr>" $commit
done
echo "</table>"

For different formatting options visit the git-show help pages.


I haven't really checked that jgit supports rev-list, but the claim on the jgit web page, as I understand it, is that it support the git core functionality. For example - see org.eclipse.jgit.revwalk.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top