kriver
kriver

Reputation: 1626

Recovering a git reset --soft

I modified some files in my branch and did a

git add --all

But this added some files that I didn't intend to add for the commit.

So I did a

git reset --soft HEAD~2 (instead of doing git reset HEAD)

But the previous commit was made by someone else and it caused a lot of files to be in modified/added/deleted status. Is there a way to get back to a stage where the only changes I see are the files added/modified by me? Since I didnt make an actual commit, is there a way to move my head back to master without blowing away my changes? git pull is causing merge conflicts as I didn't actually commit my changes.

Thanks!

Upvotes: 10

Views: 10787

Answers (3)

Paul Pladijs
Paul Pladijs

Reputation: 20506

A visual solution: open git gui:

git gui

At bottom at the Commit Message box choose the radio button labeled Amend Last Commit. You'll see at the left the Staged Changes area. It contains the files you have added in the last commit. Click on the icons of the files you don't want in your commit to remove them from the index. Afterwards just commit again by pressing the Commit button.

Upvotes: -1

Kzqai
Kzqai

Reputation: 23102

For future reference, you can review the commits that your behavior causes or leaves behind by calling git reflog , which will include commits that are no longer in your working tree.

Upvotes: 15

Dan Moulding
Dan Moulding

Reputation: 221151

Just do git reset master. This will only update the index and what HEAD points to. It will not modify your work tree files.

Upvotes: 7

Related Questions