17

After I made changes on a file. I use git add FILE_NAME.

Then, I would like to revert it as not added but meanwhile keep the changes, how to do this?

Mellon
  • 37,586
  • 78
  • 186
  • 264
  • I think it's already answered [here][1] [1]: http://stackoverflow.com/questions/936249/git-removing-a-file-from-source-control-but-not-from-the-source – Vladimir Kadalashvili Dec 05 '11 at 16:38
  • 1
    @VladimirKadalashvili No, it's not answered. Mellon wants to **unstage** file added to index before commit, not remove commited file from repository (at last that's how I understand this question) – MBO Dec 05 '11 at 16:49
  • 3
    When you do `git status` it will already say what you have to do to unstage files. – manojlds Dec 05 '11 at 19:02

4 Answers4

35

git reset -- FILE_NAME will do it.

See the git reset manual:

This means that git reset <pathspec> is the opposite of git add <pathspec>

Christoffer Hammarström
  • 27,242
  • 4
  • 49
  • 58
  • Note this works *even if the file was untracked* prior to adding, and you want to unstage (un-add) it but preserve it (keep the changes), and make it untracked again. – Will May 20 '19 at 15:18
  • 1
    `$ git reset --` to unstage everything – Daniel Jan 23 '20 at 17:09
4
git stash save 
git stash apply 

they will all be unstaged

eomeroff
  • 9,599
  • 30
  • 97
  • 138
2

you could use

git reset --mixed -- <filename>

if you use --hard, you would discard all your changes.

TheOneTeam
  • 25,806
  • 45
  • 116
  • 158
1

You can use git reset                

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
Amol Udage
  • 2,917
  • 19
  • 27