What's the best way to move your last git commit back into the "Changes not staged" + "Untracked files" areas (with the commit in question being not-pushed / only in your local repo, effectively removing it from HEAD)?
In other words, how do you roll back a commit, but automatically apply that diff to your unstaged area?
To unstage commits on Git, use the “git reset” command with the “–soft” option and specify the commit hash. Alternatively, if you want to unstage your last commit, you can the “HEAD” notation in order to revert it easily. Using the “–soft” argument, changes are kept in your working directory and index.
The closest that I know how to do is to copy all of the files that were changed in the commit to somewhere else, reset the branch to the commit before the commit that you're trying to move into the staging area, move all of the copied files back into the repository, and then add them to the staging area.
git add. The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .
You can use git reset
to set the current branch to the preceding commit, i.e. HEAD^
git reset HEAD^
Adding --soft
will keep those files in the index: (ready to be committed)
git reset --soft HEAD^
--soft
(…) This leaves all your changed files "Changes to be committed", as git status would put it.
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