Guildenstern
Guildenstern

Reputation: 3841

How to show/log all commits (and only those) from stdin?

I have a list of commits and I want git-log(1) or git-show(1) to show all of them. But only them. Not also commits that are reachable from them.

Upvotes: 0

Views: 49

Answers (1)

Guildenstern
Guildenstern

Reputation: 3841

git-log(1)

You need --stdin which lets you provide options and commits from standard in as well as the one you’ve already provided. Keep in mind that it seems that this should be the last argument that you provide.

Then you need --no-walk which stops the command from finding ancestors.

$ cat example.txt
HEAD
HEAD~2
HEAD~5
$ <example.txt git log --no-walk --stdin

Example application:

ref=commits
[ "$(git notes --ref="$ref" | head -1)" ] \
    && git notes --ref="$ref" list \
    | cut -d' ' -f 2 \
    | git log --no-walk --ignore-missing --stdin

git-show(1)

(Thanks to eftshift0)

git-show(1) will let you both show commits and other kinds of objects (the example application takes objects from Git Notes and Notes can be attached to any object).

$ cat example.txt
HEAD
HEAD~2
HEAD~5
<example.txt git show --stdin

The example application:

ref=commits
[ "$(git notes --ref="$ref" | head -1)" ] \
    && git notes --ref="$ref" list \
    | cut -d' ' -f 2 \
    | git show --ignore-missing --stdin

Upvotes: 1

Related Questions