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
user2694306
4,09010 gold badges51 silver badges99 bronze badges
-
3git reset --soft HEAD^gpullen– gpullen2014年11月03日 14:07:28 +00:00Commented Nov 3, 2014 at 14:07
-
possible duplicate of Undo the last Git commit?Andrew C– Andrew C2014年11月03日 15:03:02 +00:00Commented Nov 3, 2014 at 15:03
-
@gpullen: your solution worked. If you add it as an answer I can accept it.user2694306– user26943062014年11月03日 15:53:19 +00:00Commented Nov 3, 2014 at 15:53
-
No prob glad it helped. .gpullen– gpullen2014年11月03日 16:05:05 +00:00Commented Nov 3, 2014 at 16:05
1 Answer 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.
Sign up to request clarification or add additional context in comments.