200-901 Question 33
Single answerYou are developing a Python script that uses Git to manage a source code repository. You want to compare the changes between the working directory and the latest commit. Which command would you use to achieve this?
- A
git diff
- B
git commit
- C
git log
- D
git checkout
Show answer and explanation
Correct answer: A
Explanation
The 'git diff' command is specifically designed to show the differences between the working directory, staging area, and previous commits. In this scenario, where the goal is to compare changes with the latest commit, 'git diff' is the correct choice. Understanding how to use 'git diff' is essential for developers to track changes in their code efficiently.
- A. Correct.
The 'git diff' command is used to compare changes between the working directory and the latest commit or between two commits. This is the correct command to identify differences.
- B. Incorrect.
The 'git commit' command is used to save your changes to the local repository but does not allow you to view the differences between the working directory and the latest commit.
- C. Incorrect.
The 'git log' command shows the history of commits in a repository, but it does not provide a comparison of changes.
- D. Incorrect.
The 'git checkout' command is used to switch between branches or restore files, but it is not used for comparing changes.