cherrun cherrun - 1 year ago 101
Git Question

Reset without losing already committed files

When I accidentally committed a file to the wrong branch, I normally use

git reset --hard HEAD~1
. However, using this method I generally lose all the files committed. Is there a way to reset a commit, without losing the edited files?

Answer Source

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

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

git reset --soft HEAD^

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download