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.

4

2 回答 2

4

我总是更喜欢语法:

git reset HEAD -- a/file

(请参阅有关 ' ' 双连字符使用的答案)--

如果让git status您感到困惑,您仍然可以执行以下操作:

git diff --cached -- a/file

如果输出为空,则不会暂存该文件。

于 2013-06-17T07:07:36.670 回答
0

暂存只是跟踪您的更改。

如果你想在使用 ' git commit '后回来

使用这个:git reset --soft "HEAD^" 使用此命令后,如果您对文件进行了一些更改,该git status 命令将显示您的文件在暂存区(已跟踪),并且您的一些内容需要添加到暂存区。您需要git add <filename>再次使用该命令将您的更改添加到暂存区。

现在,如果您不想在此处进行更改并想再退一步,例如。反转“ git add

使用此:git rm --cached <filename> 在此之后,您将使用git status您的文件时显示为未跟踪。

于 2013-11-15T06:21:48.727 回答