Govur University Logo
--> --> --> -->
...

Write a single `git log` command to display the last 3 commits, each on one line, showing only the commit hash and subject, and *excludingany merge commits.



The single `git log` command to display the last 3 commits, each on one line, showing only the commit hash and subject, and excluding any merge commits is: `git log -n 3 --no-merges --pretty=format:"%h %s"`.

`git log` is a core Git command used to view the recorded history of a repository. It displays a list of commits, ordered by default from the most recent to the oldest.

`-n 3` is an option that limits the output of `git log` to a specific number of commits. In this case, `-n 3` tells Git to display only the three most recent commits in the history.

`--no-merges` is an option that filters the commit history to exclude merge commits. A merge commit is a special type of commit that is created when you combine changes from one branch into another using a command like `git merge`. These commits typically have two or more parent commits, indicating they are a confluence of different lines of development. By using `--no-merges`, only regular, linear development commits will be shown, effectively removing the commits that represent branch integrations.

`--pretty=format:"%h %s"` is an option used to customize the output format of each commit entry. The `--pretty` part indicates that a specific format will be applied to the output. The `format:` keyword specifies that a custom format string will be provided. The string `"%h %s"` defines the exact content and layout for each commit line:
`%h` is a placeholder that Git replaces with the abbreviated commit hash. The commit hash is a unique identifier for each commit, and the abbreviated form provides a shorter, more readable version suitable for single-line displays.
`%s` is a placeholder that Git replaces with the commit's subject line. The subject is the first line of a commit message, intended to be a concise summary of the changes introduced by that commit.
The space between `%h` and `%s` ensures that the abbreviated hash and the subject are separated by a space in the final output, making it easy to read. This entire `"%h %s"` string ensures that each displayed commit appears on a single line, containing only its short hash and subject.