Inspection and Comparison
git log
Description
It is used to view the commit history of a Git repository. It shows a list of commits made to the repository, including details such as commit hash, author, date, and commit message. git log
is highly customizable with various options to filter and format the output according to the needs.
Usage
Options
--oneline
: Shows each commit as a single line.
--graph
: Displays an ASCII graph of the branch and merge history.
--decorate
: Adds branch and tag names to the commit display.
--stat
: Shows the file changes (number of insertions and deletions) introduced by each commit.
-p
or --patch
: Shows the patch (diff) introduced by each commit.
--author=<author>
: Filters commits by a specific author.
--since=<date>
: Filters commits newer than a specific date.
--until=<date>
: Filters commits older than a specific date.
--grep=<pattern>
: Filters commits with a commit message that matches the given pattern
-n <number>
: Limits the number of commits to show.
What It Does
Displays Commit History: Shows a list of commits with details such as commit hash, author, date, and commit message.
Filters Commits: Allows filtering commits by author, date, message, and more.
Formats Output: Provides various options to format the output, including graphs, pretty print, and custom formats.
Common Use Cases
Example Output
When running git log
git show
Description
It is used to display detailed information about Git objects such as commits, tags, and blobs. It provides a combination of the functionalities of git log
and git diff
, showing the commit details along with the diff introduced by that commit. It is particularly useful for viewing the content changes and metadata of a specific commit or object.
Usage
Options
--pretty=<format>
: Specifies the format for displaying commit information. Possible values include oneline
, short
, medium
, full
, fuller
, email
, and raw
.
-q
or --quiet
: Suppresses diff output.
--name-only
: Shows only the names of changed files.
--name-status
: Shows the names and status of changed files.
--stat
: Shows the stats of changes (number of insertions and deletions) introduced by the commit.
What It Does
Displays Commit Information: Shows details of the specified commit, including author, date, and commit message.
Shows Changes Introduced: Displays the diff of changes introduced by the specified commit.
Common Use Cases
Example Workflow
Example Output
When running git show <commit-hash>
git blame
Description
It is used to display the last modification of each line in a file along with the commit, author, and date that introduced the change. This command is particularly useful for identifying who last changed a specific line of code, and when it was changed, which can be valuable for debugging and code review purposes.
Usage
Options
-L <start>,<end>
: Limits the blame output to the specified range of lines
-w
or --ignore-whitespace
: Ignores changes in whitespace
-C
: Detects lines that have been moved or copied within the same file
-M
: Detects lines that have been moved or copied from other files
--since=<date>
: Limits the blame output to changes made since the specified date
--until=<date>
: Limits the blame output to changes made until the specified date
--show-name
: Shows the file name in the blame output
What It Does
Annotates Each Line: Displays each line of the file with information about the commit, author, and date of the last modification.
Helps Track Changes: Identifies who made changes to specific lines and provides context for when and why the changes were made.
Common Use Cases
Example Workflow
Example Output
When running git blame path/to/file
Last updated
Was this helpful?