这个是我查到的一个文档,不知道有没有帮助:
There are a number of situations in Git where you may want to undo or revert a change that you made. Perhaps you staged a file and then decided that you didn’t want it staged, or you edited a file and then wanted to ‘un-edit’ it. This section will explore a couple of ways you can undo or revert actions in Git.
unstaging files
Here we’ve staged changes to both our REAME and simplegit.rb files, but then we decide that we want the changes to be two seperate commits. So, we need to unstage one, do a commit, then stage it again and do our second commit. Luckily, Git reminds you how to do this right in the ‘git status’ command output.
$ git status
# On branch nolimit
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README
# modified: lib/simplegit.rb
#
If you ever forget how to unstage a file, just run the ‘git status’ command to remind yourself with the (use “git reset HEAD (file)…” to unstage) text. So lets use that to unstage the README file.
$ git reset HEAD README
README: locally modified
Now if we run the ‘status’ command again, we can see that the README file is no longer staged.
$ git status
# On branch nolimit
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: lib/simplegit.rb
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README
#
If you want an easier way of remembering this, you can add an ‘unstage’ alias in your Git config file.
$ git config --global alias.unstage 'reset HEAD'
Then you can just run:
[Quote=引用 4 楼 wwwcs59 的回复:]
这个是我查到的一个文档,不知道有没有帮助:
There are a number of situations in Git where you may want to undo or revert a change that you made. Perhaps you staged a file and then decided that you didn’t want it staged, o……
[/Quote]