A file in a local Git repository has been updated and issued the git add . command. The git diff command has been run to compare the changes to the previous commit, but nothing shows. Which action identifies the problem?
A.
Run the git add . command again in the correct subdirectory to ensure changes added to the staging area.
B.
Run the git commit command before the differences are compared to receive the end state of the code.
C.
Run the git status command to see the differences between current and previous code review stages.
D.
Run the git diff --staged command to compare the code added to the staging area.
When you run the git add . command, the changes are moved to the staging area. The git diff command, by default, shows differences between the working directory and the last commit. Since the changes have been staged, git diff will not show any differences because it is comparing the working directory to the last commit, not the staging area. To see the changes that have been staged, you need to use the git diff --staged command, which compares the staged changes with the last commit.
References:
Pro Git Book, Chapter 2: Git Basics - Recording Changes to the Repository
Git Documentation
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit