Viewing the change history of a file using Git
Step 1: Check the Current Status of Repository
It’s a good practice to check the current status of the Git repository before starting to view the change history of a file.
git status
This will display the current state of the repository, including any untracked, modified, or staged files.
Step 2: View the Change History of a File
To view the change history of a particular file, use the git log command.
git log -- filename.extension
Git will only show list of commits that affected the specified file.
Step 3: View the Changes Made in a Commit
To view the changes that were made in a particular commit, we can use the git show command.
git show <commit-hash>
for me it will be like
git show 4307109352a64dcd91ebe22bd8845fb6345ff5cf
Alternative way:
git log -p -- filename
This can also be used to view the change history of a specific file in Git.
Command breakdown:
- git log: This is the base command for viewing the commit history in Git.
- -p: This option tells Git to show the diff of each commit.
- –: This option separates the commit history options from the file path.
- filename: This is the path to the file whose change history you want to view.
How to View the Change History of a File using Git Versioning?
Git is a widely used distributed version control and source code management system. It effectively tracks changes to source code, enabling effortless branching, merging, and versioning.