Reset without losing already committed files

for my case, i prefer using --mixed instead, after i found this simple explanation

git reset --mixed HEAD^

While Alex is very correct, I might be tempted to try a different sequence:

If I wanted the commit on a yet-to-be-born branch:

git branch newbranch
git reset --hard HEAD^

If I wanted the commit on an existing branch:

git checkout otherbranch
git cherry-pick firstbranch
git checkout firstbranch
git reset --hard HEAD^

The full example of Alex's answer

git reset --soft HEAD^
git checkout otherbranch
git commit -am "Message"

Note the last example will fail poorly if the attempt to "float" the change to the other branch fails due to conflicts. You will then need to stash/checkout/apply to get into conflict resolution.


do not use --hard use --soft instead.

Thus if you want to remove your latest commit you'd do:

git reset --soft HEAD^

Tags:

Git

Git Reset