Kotosif
Kotosif

Reputation: 353

View Git history before a specific commit ID in the current branch

I'd like some Git log command to list out the commits before some specific commit ID/hash in the current working branch.

E.g. Something like

git log --before <commit id>

But I haven't been able to find what the correct command to do this is.

Upvotes: 5

Views: 1205

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 21938

Just give the commit hash as the ref to explore via log

git log <commitHash>

and it will output all history from that point, backwards, until initial commit.

Alternatively, if you need to exclude this specific commit itself, then refer to its parent with

git log <commitHash>^

Sidenote about your mention of "in the current working branch"

Branches are technically irrelevant here to tree traversal logic. This won't limit output to what's "in" the branch, largely because the common metaphor is quite bad : commits are just not "on" branches. Branches are to be seen as soft (and disposable) shortcuts to designate one commit in the tree.

Upvotes: 4

Related Questions