Complete Guide to Displaying File Changes in Git Log: From Basic Commands to Advanced Configuration

Nov 11, 2025 · Programming · 14 views · 7.8

Keywords: Git log | File changes | Version control | Rename detection | Diff algorithms

Abstract: This article provides an in-depth exploration of various methods to display file change information in Git logs, including core commands like --name-only, --name-status, and --stat with their usage scenarios and output formats. By comparing with SVN's logging approach, it analyzes Git's advantages in file change tracking and extends to cover Git's rename detection mechanism, diff algorithm selection, and related configuration options. With practical examples and underlying principles, the article offers comprehensive solutions for developers to view file changes in Git logs.

Core Commands for Viewing File Changes in Git Log

In version control systems, viewing file change information in commit history is a common requirement in daily development. Similar to SVN's svn log -v command, Git provides multiple powerful options to display file information changed in each commit.

Basic File Change Viewing Commands

Git's git log command with different parameters can meet various file change viewing needs:

Display Full Paths of Changed Files

git log --name-only

This command outputs the full pathnames of all changed files in each commit, similar to SVN's -v mode but with a cleaner format.

Display File Paths and Change Status

git log --name-status

This command not only displays file paths but also adds change status indicators before each file:

Display Statistics and Abbreviated Paths

git log --stat

This command provides richer change information, including:

Comparative Analysis of Git and SVN Log Output

Although both SVN's svn log -v and Git's corresponding commands are used to display file changes, they differ significantly in implementation mechanisms and output formats. SVN directly stores complete file history, while Git, based on a snapshot mechanism, generates change information by comparing differences between commits.

Advanced File Change Tracking Features

File Rename Detection Mechanism

Git's rename detection is a feature worth exploring in depth. Unlike traditional version control systems, Git does not directly store rename operations but dynamically detects them through diff algorithms when needed.

The core process of rename detection includes:

  1. Identifying deleted files in commits as potential rename sources
  2. Identifying added files in commits as potential rename targets
  3. Using diff algorithms to calculate file similarity
  4. Determining if it's a rename based on similarity threshold

Similarity Threshold Configuration

Git uses the -M parameter to configure the similarity threshold for rename detection:

git log -M90% --name-status

The default similarity threshold is 50%, meaning Git will only recognize it as a rename when more than 50% of the file content remains unchanged.

Diff Algorithm Selection and Performance Optimization

Git provides multiple diff algorithms, each with different trade-offs between accuracy and performance:

Available Algorithm Types

Algorithm Selection Example

git log --diff-algorithm=patience --stat

Custom Output Format and Filtering

File Type Filtering

Using the --diff-filter parameter can filter specific types of file changes:

git log --name-status --diff-filter=AM

This command only shows added and modified files.

Path Limitation

You can limit the display to changes in specific directories or files:

git log --name-only -- src/

Configuration Optimization and Best Practices

Global Configuration Optimization

Git configuration can optimize default diff behavior:

git config --global diff.renames copies
git config --global diff.algorithm histogram

Alias Setup

Creating aliases for commonly used commands can improve work efficiency:

git config --global alias.logv \"log --name-status\"
git config --global alias.logs \"log --stat\"

Practical Application Scenarios

Code Review Preparation

Before code review, using git log --stat can quickly understand the scope and scale of changes, helping reviewers allocate time.

Release Note Generation

Combining --name-status with specific commit ranges can automatically generate file change lists in release notes.

Refactoring Impact Analysis

When performing large-scale refactoring, using rename detection features can accurately track file movement history.

Performance Considerations and Large Repository Optimization

In large code repositories, certain diff operations may consume significant resources. Optimization can be achieved through:

Conclusion

Git provides rich and flexible tools for viewing file changes, from simple --name-only to complex rename detection, meeting needs in different scenarios. Understanding how these tools work and their applicable scenarios can help developers use Git more efficiently for version control and code management. Through proper configuration and command combinations, Git's file change tracking capabilities far exceed those of traditional version control systems, providing powerful support for modern software development.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.