Junior — Middle
How can you undo the very last commit in a version control system?
sobes.tech AI
Answer from AI
To undo the very last commit in the Git version control system, you can use the command:
git reset --soft HEAD~1
This command will undo the last commit but keep the changes in the index (staging area), so you can modify and commit them again if needed.
If you want to undo the commit and remove the changes from the index but keep them in the working directory:
git reset --mixed HEAD~1
If you want to completely delete the last commit and changes (Use with caution!):
git reset --hard HEAD~1
You can also use git revert HEAD to create a new commit that undoes the changes of the previous one, which is safer for public branches.