How do you show changes between a commit and the working directory?
Posted by LeoRobs
Last Updated: June 23, 2024
To show changes between a commit and the working directory in Git, you can use the git diff command. Here's how you can do it: 1. Show changes between the last commit and the working directory: If you want to compare the current working directory against the most recent commit (HEAD), you can use:
git diff
2. Show changes between a specific commit and the working directory: If you want to compare a specific commit (e.g., abc1234) with the working directory, you can specify the commit hash:
git diff abc1234
3. Show changes between a commit and the staging area: If you also want to see changes between the working directory and what's staged for the next commit (index), you can use:
git diff --cached
4. Show changes between a commit and what's staged: If you want to compare a specific commit with the staged changes, you can combine the commit reference with the --cached option:
git diff abc1234 --cached
5. Viewing a specific file's changes: If you want to see changes for a specific file, you can specify it:
git diff path/to/file
By using these commands, you can effectively view the differences between your working directory and a specific commit in your Git repository.