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.
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:
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:
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:
Example Output
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.
| Feature | svn log -v | git log with Customization |
| Default Filename Display | Yes | No
Requires --name-status or --name-only |
| Status Display (Add/Modify) | Yes | Yes
Combine with --name-status |
| Date Format | Fixed | Customizable
via --pretty |
| Author Information | Displayed | Displayed Customizable |
| Command Customization | Limited | Extensive
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:
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:
Additionally, filter results by specific files using:
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
- How to ignore certain files in Git
- How to ignore certain files in Git
- How to import a GIT non-Eclipse Java project into Eclipse?
- How to import existing Git repository into another?
- How to install a specific Chart version
- How to install an npm package from GitHub directly
- How to install git on a docker ubuntu image?
- How to install Python package from GitHub?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.