You have just realized that the last two commits on your local feature branch contain the correct code, but you want to combine them into a single, better-described commit before pushing the branch. Your goal is to move HEAD back two commits while leaving all of the changes staged so you can create the new commit immediately. Which single Git command accomplishes this?
The --soft mode of git reset moves the HEAD pointer to the specified commit without touching either the index (staging area) or the working directory. Therefore git reset --soft HEAD~2 rewinds the branch two commits while keeping all of the intervening changes staged, allowing you to commit them again (for example with git commit --amend or a fresh git commit).
git reset --mixed HEAD~2 would also move HEAD, but it unstages the changes, requiring you to run git add again.
git reset --hard HEAD~2 rewinds HEADand resets both the index and working tree, discarding the changes entirely.
git revert HEAD~2..HEAD does not move HEAD; instead it creates new commits that reverse the effects of the specified range, leaving the original commits in history.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of `git reset --soft`?
Open an interactive chat with Bash
How is `git reset --soft` different from `git reset --mixed` and `git reset --hard`?
Open an interactive chat with Bash
When should you use `git reset --soft` instead of `git revert`?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .