Exclude Preceding Commit> line from git rev-list f

2020-08-11 10:26发布

I'm trying to work on a branch diff command, and I've got it all working... Except for the formatting. I can use --pretty=oneline to display just the information I want, except it displays the full hash, and doesn't colorize the output.

So it'd just output this:

fa73c05913292fbce940075fc8f454bad5066666 Example Commit Message
de4dbeffa249393dddebb7b13ae555cb97cad5be Another Example Commit Message

If I try and do a custom format string, such as this: --pretty="format:%C(yellow)%h%C(reset) %s", it works, but it also displays an additional line above it.

E.g.

commit >fa73c05913292fbce940075fc8f454bad5066666
fa73c05 Example Commit Message
commit >de4dbeffa249393dddebb7b13ae555cb97cad5be
de4dbef Another Example Commit Message

Is there a way to have git rev-list output a format without the preceding commit >abcdef3... lines?

标签: git
3条回答
叛逆
2楼-- · 2020-08-11 11:00

To leave an answer for those who will come next/

@torec mentioned in his comment the following:

git rev-list and git log are essentially the same command

The answer is to use the following format:

# print out the log history in the desired format.
git log --pretty="format:..." <SHA-1>
查看更多
太酷不给撩
3楼-- · 2020-08-11 11:03

You can use sed after git rev-list to delete all the lines starting with commit.

git rev-list --pretty=format:"%C(yellow)%h%C(reset) %s" | sed '/^commit/d'.

查看更多
【Aperson】
4楼-- · 2020-08-11 11:07

There is literally no way to do this, unfortunately. git rev-list is implemented thusly:

    if (revs->abbrev_commit && revs->abbrev)
        fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev),
              stdout);
    else
        fputs(oid_to_hex(&commit->object.oid), stdout);

so no matter what options you put in, git rev-list will always print some kind of commit hash.

查看更多
登录 后发表回答