简体   繁体   中英

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

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 (ie pull a commit out from between other commits).

git reset --soft HEAD~1
git stash save "Saving instead" # or something like that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM