Git - git log

git

git log --first-parent <branch_name> // display log messages for the current branch or given branch name
git log --graph --abbrev-commit --decorate  --first-parent <branch_name>
git log --since='3 days ago' // review commit logs
git log -10 // show up to 10 commits
git log --until=2005-12-10

What is the purpose of the 'git log' command?

# by name
git log v1.0.0   # show history leading up to tag "v1.0.0"
git log master   # show history of branch "master"

What is the purpose of the 'git log -p' option?

If you also want to see complete diffs at each step, use

git log -p

What is the purpose of the 'git log —stat —summary' options?

Often the overview of the change is useful to get a feel of each step:

git log --stat --summary

What is the weakness with the 'git log' command?

The git log command has a weakness: it must present commits in a list. When the history has lines of development that diverged and then merged back together, the order in which git log presents those commits is meaningless.

Most projects with multiple contributors (such as the Linux kernel, or Git itself) have frequent merges, and gitk does a better job of visualizing their history. For example:

gitk --since="2 weeks ago" drivers/

The above command allows you to browse any commits from the last 2 weeks of commits that modified files under the "drivers" directory. (Note: you can adjust gitk’s fonts by holding down the control key while pressing "-" or "+".)

What is the purpose of the 'git log -S' option?

shows the commits which add or remove any file data matching a string:

git log -Sstring

How can we view the commit log messages?

git log

How can we display the last 3 commit messages?

git log -n 3

How can we display the commit log messages along with the files that were part of each commit?

git log --stat

This command results in the display of regular git log information, as well as information on which files underwent modification and the relative numbers of line deletions and additions from each of them.

How can we see a full diff with each commit log message?

git log -p

How can we display a list of commit log messages containing a particular string?

git log --grep="updated"

How can we display a list of commit log messages from a particular author?

git log --author="smith"

The command above allows for a specific search for commits by an author whose name includes the string “smith.”

How can we display a list of commit log messages involving a particular file?

git log index.html

What is the purpose of the 'git log --oneline' command?

This command presents repository information in a single line, so you can get a high-level overview.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License