A developer is preparing a commit. They have modified a tracked file named config.yml and used git add config.yml to stage the changes. Before committing, the developer makes additional, separate modifications to the same config.yml file. Which of the following commands must the developer use to view only the changes that are staged for the next commit, while excluding the most recent unstaged modifications?
The correct command is git diff --staged. This command specifically shows the difference between the files in the staging area (the index) and the last commit (HEAD). In this scenario, it will display only the changes that were added with git add config.yml.
git diff shows the changes between the working directory and the staging area. It would display the unstaged modifications, not the staged ones.
git diff HEAD shows all changes between the working directory and the last commit, which would include both the staged and unstaged modifications together.
git log -p is used to review the commit history, showing the full patch (diff) for each commit, but it does not show pending changes in the staging area.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `git diff --staged` command do?
Open an interactive chat with Bash
How is `git diff` different from `git diff --staged`?
Open an interactive chat with Bash
When should a developer use `git diff HEAD` instead of `git diff --staged`?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access