1、撤销在工作区的修改
分为两种情况:
(1)如果readme.txt修改后还没有放到暂存区,就撤销回和分支中相同的状态
(2)如果readme.txt修改后被放到了暂存区,然后又在工作区进行了修改,就撤销回和暂存区相同的状态
例子:
修改readme.txt文件为:
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
My stupid boss still prefers SVN.

$ git checkout -- readme.txt
2、从暂存区撤销修改
修改readme.txt文件为
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
My stupid boss still prefers SVN.
将修改加入到暂存区

将修改从暂存区撤销,重新放回工作区
git reset HEAD readme.txt

之后如第1部分所述可以丢掉工作区的修改

3、将提交到分支的修改撤销
参考版本回退。
浙公网安备 33010602011771号