0

I accidentally committed all files with the command

git commit -m "Message" .

Where I wanted to actually run

git commit -m "Message" ./file

I haven't yet done a git push. How can I undo the last commit so all of these files don't get pushed?

asked Nov 3, 2014 at 13:58
4
  • 3
    git reset --soft HEAD^ Commented Nov 3, 2014 at 14:07
  • possible duplicate of Undo the last Git commit? Commented Nov 3, 2014 at 15:03
  • @gpullen: your solution worked. If you add it as an answer I can accept it. Commented Nov 3, 2014 at 15:53
  • No prob glad it helped. . Commented Nov 3, 2014 at 16:05

1 Answer 1

1

Use

git reset --soft HEAD^

For information, the git-reset command resets the current branch to the specified commit (HEAD^, here).

As for the --soft option, it does not touch the index file nor the working tree at all, but requires them to be in a good order. This leaves all your changed files "Changes to be committed".

For more information, see the git-reset man page.

jub0bs
67.3k27 gold badges198 silver badges200 bronze badges
answered Nov 3, 2014 at 15:57
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.