A developer accidentally committed a file that should not be tracked by Git. What command should they use to rectify this before pushing?

  • git reset HEAD
  • git rm --cached
  • git checkout -- filename
  • git revert
The correct option is c. git checkout -- filename. This command discards changes in the working directory and unstages the file, effectively "uncommitting" it. git reset HEAD and git rm --cached are used for different purposes. git reset HEAD unstages changes, and git rm --cached unstages the file but also stages the removal. git revert is used to create a new commit that undoes a previous commit.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *