Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.17 KB

index.md

File metadata and controls

52 lines (36 loc) · 1.17 KB

git branch-commit-prev

Show a branch's previous commit hash (or hashes)

Git alias:

branch-commit-prev = "!f() { \
    branch="${1:-$(git current-branch)}"; \
    count="${2:-1}"; \
    git log --pretty=%H "$branch" | \
    grep -A "$count" $(git rev-parse HEAD) | \
    tail +2; \
}; f"

Syntax:

git branch-commit-prev [branch name [commit count]]

Options:

  • branch name: default is the current branch name.

  • commit count: default is 1

Example: show the current branch's previous commit hash:

git branch-commit-prev

Example: show the "foo" branch's previous commit hash:

git branch-commit-prev previous

Example: show the "foo" branch's previous 3 commit hashes:

git branch-commit-prev foo 3

Compare: