git
git log
version control
svn
file tracking

How to have 'git log' show filenames like 'svn log -v'

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

When transitioning from Subversion (SVN) to Git, many developers seek to replicate familiar functionalities, such as the comprehensive svn log -v command. This powerful SVN command provides a detailed output of commit information, including filenames. While Git's git log provides extensive commit history insights, it doesn't display changed filenames by default. However, Git offers configurations and tweaks to achieve similar results.

Understanding git log

The git log command in Git provides a record of commits in a repository's history. By default, it outputs essential information like the commit hash, author, date, and commit message. However, it can be customized to display additional details like filenames, making it similar to svn log -v.

Displaying Filenames with git log

Basic Command

To mimic svn log -v behavior, you can use the --name-status or --name-only flags with git log.

  • --name-status: Shows the status of each file (e.g., added, modified, deleted).
  • --name-only: Lists the filenames without the status.

Example:

bash
git log --name-status

This command outputs commit logs along with the status and names of files affected by each commit.

Formatted Output

For a more structured display, use --pretty to customize the commit message format. Combine it with the --name-status flag for comprehensive output:

bash
git log --pretty=format:"Commit: %h %nAuthor: %an %nDate: %ad %nMessage: %s" --name-status

Explanation:

  • %h: Shortened commit hash
  • %n: New line
  • %an: Author name
  • %ad: Author date
  • %s: Commit subject

Additional Customizations

Git allows you to format the dates, authors, and even change the default name status indicators using command options, making it as verbose or concise as needed. For example:

To display dates in a relative format:

bash
git log --pretty=format:"Commit: %h %nAuthor: %an %nDate: %ar %nMessage: %s" --name-status

Example Output

plaintext
1Commit: 1a2b3c4
2Author: Jane Doe
3Date: 2 days ago
4Message: Update README
5
6M       README.md
7A       new_file.txt
8
9Commit: 5d6e7f8
10Author: John Doe
11Date: 4 days ago
12Message: Initial commit
13
14A       .gitignore
15A       main.py

Comparing svn log -v and Customized git log

The table below summarizes the key differences and configurations available with svn log -v and git log.

Featuresvn log -vgit log with Customization
Default Filename DisplayYesNo Requires --name-status or --name-only
Status Display (Add/Modify)YesYes Combine with --name-status
Date FormatFixedCustomizable via --pretty
Author InformationDisplayedDisplayed Customizable
Command CustomizationLimitedExtensive via --pretty, --format

Additional Tips

Aliasing Commands

To streamline operations, consider creating an alias for git commands that emulate svn log -v. To set up an alias, add the following line to your ~/.gitconfig file under the [alias] section:

plaintext
svlog = log --pretty=format:"%C(red)Commit: %h%Creset%n%C(yellow)Author: %an%Creset%n%C(cyan)Date: %ad%Creset%n%C(green)Message: %s%Creset" --name-status

Now, executing git svlog offers a customized log output.

Handling Large Outputs

For repositories with extensive histories, viewing all commits at once can be overwhelming. Utilize pagination by appending | less to your commands:

bash
git log --name-status | less

Additionally, filter results by specific files using:

bash
git log --name-status -- filename.txt

Conclusion

While Git and SVN are fundamentally different in their operations and structures, it's possible to mimic many SVN functionalities within Git. By leveraging Git's customization options, you can transform git log to closely resemble svn log -v, making the transition between these two systems smoother. With the right combinations and customizations, developers can tailor Git to suit their workflow preferences seamlessly.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.