How do I view the history of an individual file with complete details of what has changed? git log -- [filename] shows me the commit history of a file, but how do I see the file content that changed?

 

To view the complete details of what has changed in an individual file throughout its commit history, you can use the git log command in combination with the git show command. Here's how you can do it:

sh
git log -p -- [filename]

Let's go through an example:

Suppose you have a file named example.txt that you want to examine the commit history and changes for.

  1. View Commit History with Changes:

    Run the following command to view the commit history of the example.txt file along with the changes made in each commit:

    sh
  • git log -p -- example.txt

    This will display a list of commits related to the example.txt file, along with the changes made in each commit.

  • View Specific Commit Changes:

    To view the complete details of changes for a specific commit, you can use the git show command:

    sh
    1. git show [commit_hash]:example.txt

      Replace [commit_hash] with the actual commit hash you want to examine. This command will show the content changes introduced in that specific commit for the example.txt file.

    By using the git log -p -- [filename] command, you can view the commit history of the file along with the detailed changes for each commit. And by using the git show [commit_hash]:[filename] command, you can view the specific content changes introduced in a particular commit for the specified file.

    Comments