I have a branch called feat-a
and I essentially want to "undo" my last local commit and just have those files staged. Then when they are all staged I want to stash those changes.
Now what I'm doing does sound a bit backwards, but the cause of this issue was a force push on master to re-write some commit authors, so doing a merge or rebase of master onto/into feat-a
just completely breaks with a ton of conflicts even though master and feat-a are only off by one commit.
I have read through a similar question here: How to stash my previous commit?
But it isn't necessarily what I want to do. I just want to unstage and stash my last direct commit, versus what that user wanted (i.e. pull a commit out from between other commits).
In order to undo the last Git commit, keep changes in the working directory but NOT in the index, you have to use the “git reset” command with the “–mixed” option. Next to this command, simply append “HEAD~1” for the last commit.
To undo a git stash , use the git stash pop command. It will re-apply your stash to your working copy.
The revert command You can find the name of the commit you want to revert using git log . The first commit that's described there is the last commit created. Then you can copy from there the alphanumerical name and use that in the revert command.
git reset --soft HEAD~1 git stash save "Saving instead" # or something like that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With