How do you discard changes from the staging area in Git?

How do you discard changes from the staging area in Git?

a) git remove file
b) git reset HEAD file
c) git revert HEAD file
d) git clean -f file

Answer:

b) git reset HEAD file

Explanation:

The git reset HEAD file command removes a file from the staging area without deleting the changes in the working directory. This allows you to unstage the file but keep the changes intact locally.

For example, if you’ve staged file.txt and decide you don’t want to include it in the next commit, you can run git reset HEAD file.txt to remove it from the staging area.

This command is useful for managing the content that will be included in the next commit without losing any changes in the file.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top