“git whatchanged” Command Examples

The “git whatchanged” command in Git is used to display information about recent commits, emphasizing the changes made to each commit or file. This command provides a detailed summary of the commit history, including commit messages and the list of files modified in each commit. It can be a useful tool for reviewing the history of a Git repository and gaining insights into what has changed over time. Here’s a more detailed explanation of what you can do with git whatchanged:

Displaying Commit Information: By default, git whatchanged lists the commits in reverse chronological order, showing the most recent commits first. For each commit, it displays information such as the commit hash, author, date, and commit message.

# git whatchanged

This provides a quick overview of the recent commit history, making it easy to see who made the changes and when.

Listing Modified Files: One of the key features of git whatchanged is its ability to list the files modified in each commit. This is particularly useful for understanding what changes were made in each commit without having to view the entire diff.

# git whatchanged --stat

The –stat option provides a summary of changes, showing the number of insertions and deletions for each file modified in a commit.

Viewing Detailed Changes: In addition to listing modified files, you can use the -p or –patch option to display the detailed changes (diff) made to each file in each commit.

# git whatchanged -p

This can be valuable when you want to inspect the exact lines of code that were added, modified, or deleted in a specific commit.

Filtering by Range: You can limit the range of commits displayed by specifying a commit range. For example, to view changes between two specific commits, you can use the commit hash or branch names.

# git whatchanged commit1..commit2

This allows you to focus on a specific subset of commits in the history.

Custom Output Format: The git whatchanged command allows you to specify a custom output format using the –pretty option. This can be helpful for generating machine-readable or custom-formatted output.

# git whatchanged --pretty=format:"%h - %an, %ar : %s"

Understanding Repository Evolution: git whatchanged is a tool for understanding how a Git repository has evolved over time. It can be especially useful for tracking changes in collaborative projects or when reviewing the history of a codebase.

Legacy Command: It’s worth noting that git whatchanged is considered a legacy command, and its functionality is largely covered by the more versatile git log command, which provides similar information in a more flexible and feature-rich manner. In most cases, git log is preferred for examining commit history.

“git whatchanged” Command Examples

1. Display logs and changes for recent commits:

# git whatchanged

2. Display logs and changes for recent commits within the specified time frame:

# git whatchanged --since="2 hours ago"

3. Display logs and changes for recent commits for specific files or directories:

# git whatchanged /path/to/file_or_directory

Summary

In summary, git whatchanged is a Git command that provides a summarized view of recent commits and the changes made to files in each commit. While it can be a useful tool for reviewing history, it’s important to note that it is considered a legacy command, and git log is typically the preferred command for examining commit history in a more flexible and comprehensive way. For detailed information on the git whatchanged command and its options, you can refer to the official Git documentation at https://git-scm.com/docs/git-whatchanged.

Related Post