Kasyx
Kasyx

Reputation: 3200

git log excluding 100+ commits

I have a list of 100+ commit IDs. I'd like to git log my whole repo but I need to exclude these mentioned commits.

I know, there is git log --grep=something but I can't imagine how this command would look like with 100+ elements. Is there a simpler way to achieve it?

Upvotes: 0

Views: 297

Answers (2)

basin
basin

Reputation: 4190

Suppose you have log format format:

--pretty="%H [%ad] - %s"

and the list of commits in the file exclude.lst, each commit on new line;
Then to exclude these commits, use:

# generate the sed program to exclude
while read c; do
    echo "/^$c /D"
done > /tmp/exclude.sed < exclude.lst

# filter out
git log --pretty="%H [%ad] - %s" | sed -f /tmp/exclude.sed

Upvotes: 1

Shahbaz
Shahbaz

Reputation: 47493

grep has the right options for you. From the man page of grep:

-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing. (-f is specified by POSIX.)

-v, --invert-match
Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)

So you can simply do:

git log --pretty=oneline | grep -v -f list_to_exclude

Upvotes: 2

Related Questions