Git Log

In Git, the log command is used to display the commit history for a repository. By default, git log displays the commit hashes, author information, and commit messages for all commits in the current branch, starting with the most recent commit.

Here's an example of how to use git log:

$ git log 

This will display the commit history for the current branch, with the most recent commit at the top.

You can use a number of options to customize the output of git log. For example, you can use the --oneline option to display each commit on a single line:

$ git log --oneline 

You can also use the --author option to filter the output by author:

$ git log --author="John Doe" 

This will only display commits that were authored by "John Doe".

There are many other options available for customizing the output of git log. You can use the --help option to see a full list of available options:

$ git log --help

Here are a few additional things to keep in mind when using git log:

  • You can use the -p or --patch option to display the changes introduced by each commit. This can be useful for reviewing the changes made in a particular commit.

  • You can use the --since and --until options to filter the output by date. For example, you can use the following command to display commits made in the past week:

$ git log --since="1 week ago" 
  • You can use the --grep option to search the commit messages for a particular pattern. For example, you can use the following command to find commits that contain the word "fix":
$ git log --grep="fix" 
  • You can use the --graph option to display the commit history as a graph, showing the relationships between commits. This can be useful for visualizing the branching and merging history of a repository.
  • You can use the --follow option to display the commit history of a file, including commits that moved or renamed the file. This can be useful for tracking the history of a particular file over time.

  • You can use the --pretty option to customize the output format of git log. This can be useful for generating output that is easier to parse or read. For example, you can use the following command to display the commit hash, author name, and subject line of each commit:

  • $ git log --pretty=format:"%h %an %s" 
  • You can use the --stat option to display a summary of the changes introduced by each commit, including the number of lines added and removed.

  • You can use the --reverse option to display the commit history in reverse order, with the oldest commit at the top.