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
  • 35,610
  • 77
  • 182
  • 262
  • 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
  • 2
    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

33

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
  • 26,003
  • 4
  • 45
  • 56
  • 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,283
  • 28
  • 92
  • 134
2

you could use

git reset --mixed -- <filename>

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

TheOneTeam
  • 24,336
  • 44
  • 110
  • 154
1

You can use git reset                

de-russification
  • 31,008
  • 6
  • 34
  • 52
Amol Udage
  • 2,707
  • 17
  • 26