本文介绍了如何将未提交到暂存区的代码进行撤销
撤销指令
git restore <file>...
后面可以指定路径或者文件。
例如:
#撤销当前文件夹的修改,可以这样写:
git restore ./
#撤销main.cpp的修改
git restore main.cpp
#撤销a.cpp和b.cpp的修改
git restore a.cpp b.cpp
实例
在需要撤销的代码仓库中输入git status指令,git会给出提交和撤销的方法,如下所示:
$ git status
On branch ui
Your branch is up to date with 'origin/ui'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: include/pcsparamsetdlg.h
modified: policyctrl.pro
modified: source/pcsparamsetdlg.cpp
modified: ui/qpcsparamsetdlg.ui
modified: ui/qpcsparamsetdlg.ui.bak
Untracked files:
(use "git add <file>..." to include in what will be committed)
policyctrl.positions
no changes added to commit (use "git add" and/or "git commit -a")
g
git status给出了修改过的文件,以及如何提交修改和撤销修改,这里撤销修改的方式就是:
git restore <file>...
执行git restore指令,即可撤销未提交的更改
$ git restore ./
撤销当前文件夹下的所有修改
撤销成功