Git - Soft Reset

Every so often, I foobar something in git and accidentally add a bunch of crap to the repo. Traditionally and ignorantly, I've just done a git reset --hard and lose my work, which was OK. However, I came to a point where I could NOT lose my work. Solution:

git reset --soft HEAD^

The above command basically undoes your previous commit and puts everything back onto staging. Particularly, HEAD^ is the identifier of that state prior to the commit.

Ref: git-reset man pages

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question? Are you human?
6 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.