Developing Applications and Automating Workflows Using Cisco Platforms (DEVASC) — Question 378
Which command reverses the last commit without changing the index file or the working tree position?
Answer options
- A. git revert HEAD
- B. git reset --hard HEAD~3
- C. git reset --soft HEAD^
- D. git revert
Correct answer: C
Explanation
The command 'git reset --soft HEAD^' is correct because it undoes the last commit while leaving both the index and working directory unchanged. In contrast, 'git revert HEAD' creates a new commit that undoes the changes of the last commit, while 'git reset --hard HEAD~3' completely discards the last three commits along with any changes, and 'git revert' without specifying a commit defaults to the last commit, which is not the same as the correct answer.