Navigate a file's history
To go back in time through a file's commit history in Git, you can use git log and git checkout commands. Here's the concise process:
- View the file's commit history:
- Check out a specific previous version:
git checkout <commit> -- <path>
Restores a file or directory to its state from a specific commit.
Or to see the contents without checking out:
git show <commit>:<path>
Display the contents of a file as it existed in a specified commit.
To restore to the previous version of the file:
git checkout HEAD <path>
Restore a file from the most recent commit
You can also use git blame to see line-by-line commit history:
git blame <path>
Show who last changed each line of a file and in which commit.