2

I have added a bunch of files in my staging area. Now I realize that I want to commit some of those files, but not others (I want to stash the rest, actually). How can I unstage some files, but leave them in the working dir so that I can do other things with them (like stashing)? For the sake of discussion, let's say I have this git status:

# On branch develop
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   app/scripts/vendor/ember-1.0.0-rc.5.js
#   deleted:    node_modules/grunt-contrib-handlebars/test/expected/partials_use_namespace.js
#   modified:   package.json
#   modified:   ../python_modules/config/settings1.py
#

Let's say I want to unstage package.json. How can I do that? I have tried with:

git reset HEAD package.json

as suggested by git itself, but has no effect: the file stays in the staging area (bug?).

To be clear, I do not want to loose the changes I have made to package.json: I simply do not want to commit them yet.

EDIT

This was a mistake on my side: my git status was so big, I could not see the Changes not staged for commit heading. That is where the unstaged files have been moved to, and that is what I wanted.

blueFast
  • 41,341
  • 63
  • 198
  • 344
  • the file after reset goes to untrack status, it won't go into your commit. – amitchhajer Jun 17 '13 at 05:47
  • 3
    `git reset HEAD` is the correct approach. [Extraordinary claims require extraordinary evidence](http://www.catb.org/~esr/faqs/smart-questions.html#idp5249360) - it is not very likely this is really a bug in `git`. Provide more information, e.g. the `git status` output after you run `git reset HEAD`, the value of `core.autocrlf` setting, and anything else you can think of. – DCoder Jun 17 '13 at 05:49
  • 1
    Can you reproduce this? `touch something && git add something && git reset HEAD something`? – 1615903 Jun 17 '13 at 05:49
  • Indeed, it gets unstaged. My git status was so big, I could not see the "Changes not staged for commit" heading. That is where the unstaged files have been moved to, and that is what I wanted. So, my bad. – blueFast Jun 17 '13 at 06:11

2 Answers2

4

I always prefer the syntax:

git reset HEAD -- a/file

(see this answer on the '--' double hyphen use)

If the git status confuses you, you still can do a:

git diff --cached -- a/file

If the output is empty, then that file is not staged.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Staging is just that your changes are being tracked.

If u want to come back after using 'git commit'

Use this: git reset --soft "HEAD^" After using this command if you make some changes to your file, the git status command will show that your file is in staging area(tracked) and some of your content needs to be added to the staging area. You need to use the git add <filename> command again to add your changes to the staging area.

Now, if you do not want to make changes here and want to come one more step back, ex. reversing the 'git add'

Use this: git rm --cached <filename> After this when you'll use git status your file be shown as not tracked.

Jyoti Prakash
  • 3,921
  • 3
  • 21
  • 24