git reset用法二 替换文件

git reset的第二种用法不是用于重置引用的,而是为了能够将某个历史版本中的文件拿出来,替换当前staging中的同名文件。

其实就是第一种用法使用了默认参数--mixed。因为很常用,所以单独提出来。

比如

git reset 

就是用仓库中当前版本的文件(位于.git/objects目录下)替换掉staging中的文件。相当于撤销上一次git add的作用。

比如我们在x文件中添加一些内容,然后用下面的命令:

$ git add -u
$ git reset
Unstaged changes after reset:
M	x
$ git commit -m'change x file'
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   x
#
no changes added to commit (use "git add" and/or "git commit -a")

git reset撤销了之前对staging区域的操作,因此git commit就提示staging区域没有什么需要提交的。


git reset HEAD 命令和 git reset相同。


还可更加精确的指定文件名,只对某个文件执行撤销操作。

$ git reset -- ~/work/189/appengine/x

注意中间用--间隔开,后面可以输入文件的完整路径。



你可能感兴趣的:(git,File,branch)