Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to undo git add before commit [duplicate]

Possible Duplicate:
Undo git add before commit

When i was working on my project I accidently added files using the following command

git add file 

I haven't yet run

git commit. 

How can I undo or remove these newly added files from the commit?

Please help.

like image 549
Surinder ツ Avatar asked Dec 29 '12 04:12

Surinder ツ


People also ask

How do you undo a git add before commit?

To undo git add before a commit, run git reset <file> or git reset to unstage all changes.

How do I undo previous commit?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.

Can you Unstage a commit?

To unstage commits on Git, use the “git reset” command with the “–soft” option and specify the commit hash. Alternatively, if you want to unstage your last commit, you can the “HEAD” notation in order to revert it easily. Using the “–soft” argument, changes are kept in your working directory and index.


1 Answers

git reset is a literally "undo" of git add - it removes the changes from staged area.

like image 164
aragaer Avatar answered Sep 28 '22 02:09

aragaer