Imagine you accidentally committed a file with sensitive information. What is the main reason knowing how to undo changes in Git is crucial?
Think about what happens if wrong changes get shared with others.
Knowing how to undo changes helps you fix mistakes before they affect others. It prevents errors from spreading and keeps the project clean.
You run git reset --soft HEAD~1 to undo your last commit but keep changes staged. What will git status show next?
git reset --soft HEAD~1 git status
Soft reset moves HEAD back but keeps changes staged.
The soft reset removes the last commit but keeps the changes staged, so git status shows them ready to commit again.
You pushed a commit that introduced a bug. You want to undo it safely without rewriting history. Which command sequence is correct?
Think about safe ways to undo changes already shared with others.
git revert creates a new commit that undoes the changes, preserving history and avoiding problems for others.
You run git reset --hard HEAD~1 but Git refuses and shows an error. What is the likely cause?
Think about what happens to uncommitted work during a hard reset.
A hard reset discards uncommitted changes. Git blocks it to prevent accidental data loss.
In a team project, what is the best practice to undo a mistake after pushing commits?
Consider how to keep history intact for your teammates.
Reverting creates a new commit that undoes changes without rewriting history, which is safer for shared work.