Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I undo my last commit in Git and stash those changes instead?

Tags:

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).

like image 406
stacksonstacks Avatar asked Oct 11 '18 13:10

stacksonstacks


People also ask

How do I revert my last commit but keep changes?

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.

How do you undo commit and stash changes?

To undo a git stash , use the git stash pop command. It will re-apply your stash to your working copy.

Can we revert the last commit in git?

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.


1 Answers

git reset --soft HEAD~1 git stash save "Saving instead" # or something like that 
like image 50
eftshift0 Avatar answered Oct 12 '22 23:10

eftshift0