Git log quickly and easily

These are some git log commands I use everyday and I think they are helpful for you.

1
    git log
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    # Get last n commits
    git log -n 5

    ## Filter by dates
    # show commits from the past two weeks
    git log --since="2 weeks ago"
    # or by using --after
    git log --after="2 weeks ago"

    # show commits until January 1, 2024
    git log --until="2024-01-01"
    # or by using --before
    git log --before="2024-01-01"

    # get commits from a specific author
    git log --author="Author Name"

    # show commits with "fix" in the message
    git log --grep="fix"

You can also format the log messages by using the --pretty option.

  • oneline: Displays each commit on a single line.
  • short: Includes commit hash, author, date, and subject.
  • medium: Adds commit message and file changes.
  • full: Includes full commit information.
  • format: Allows custom formatting using placeholders (e.g., %H for commit hash, %an for author name, %s for subject).
1
2
3
4
5
    # show concise logs
    git log --pretty=oneline
    # custom format
    git log --pretty=format:"%h - %s"
    git log --pretty=format:"Commit: %H\nAuthor: %an\nDate: %ad\nSubject: %s\n\n%b"
  • %H Commit hash
  • %h Abbreviated commit hash
  • %T Tree hash
  • %t Abbreviated tree hash
  • %P Parent hashes
  • %p Abbreviated parent hashes
  • %an Author name
  • %ae Author email
  • %ad Author date (format respects the –date=option)
  • %ar Author date, relative
  • %cn Committer name
  • %ce Committer email
  • %cd Committer date
  • %cr Committer date, relative
  • %s Subject
  • --graph: Display a commit graph.
  • --reverse: Show commits in chronological order (oldest first).
  • --no-merges: Exclude merge commits.
  • --oneline: Show commit in one-line

    And the last thing: You can combine multiple options

Related Content