Track History of Files

Tracking the history of files in Git Bash involves using various Git commands to view changes, commits, and revisions. Here's a step-by-step guide:

  1. Navigate to the Repository: Open Git Bash and navigate to the root directory of your Git repository using the cd command.

  2. View File History: Use the git log command followed by the filename to view the commit history of a specific file. For instance:

    git log filename.ext
    
  3. View Detailed Changes: To see detailed changes made to a file in each commit, you can use the git log -p command followed by the filename:

    git log -p filename.ext
    
  4. View Changes in a Specific Commit: If you want to see the changes made to a file in a particular commit, use the git show command followed by the commit hash and filename:

    git show commit_hash:path/to/filename.ext
    
  5. View Changes Over Time: You can use the git blame command followed by the filename to see which commit and author last modified each line of a file:

    git blame filename.ext
    
  6. Comparing Versions: To compare the changes between two commits for a specific file, you can use the git diff command along with the commit hashes and filename:

    git diff commit_hash1 commit_hash2 -- filename.ext
    
  7. Walkthrough of the Code: Let's say you want to view the history of changes for a file named script.py. You can use the following commands:

    git log script.py         # View commit history
    git log -p script.py      # View detailed changes in commits
    git show commit_hash:path/to/script.py   # View changes in a specific commit
    git blame script.py       # Identify the commit and author of each line
    git diff commit_hash1 commit_hash2 -- script.py   # Compare changes between commits
    
    

Remember to replace filename.ext, commit_hash, and path/to/filename.ext with the actual filename and commit hashes you're interested in. This should help you effectively track the history of files in your Git repository using Git Bash.