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?

user2694306
  • 3,832
  • 10
  • 47
  • 95

1 Answers1

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
  • 60,866
  • 25
  • 183
  • 186
gpullen
  • 1,093
  • 2
  • 14
  • 28