git如何撤销未提交的更改

本文介绍了如何将未提交到暂存区的代码进行撤销

撤销指令

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 ./
撤销当前文件夹下的所有修改

撤销成功
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值