#### 1. 前言 --- git restore 用于恢复工作树文件。应用场景: 取消暂存、放弃更改 #### 2. 使用示例 --- 初始化一个 git 仓库,并且完成一次提交 ``` git init echo Index.php >> Index.php git add Index.php git commit -m 'add Index.php' ``` 修改文件内容 ``` # 修改文件内容 echo abc >> Index.php # 查看内容 cat Index.php # 查看状态 git status ``` 放弃更改 ``` git restore Index.php ``` 修改文件内容 ``` # 修改文件内容 echo abc >> Index.php # 查看内容 cat Index.php # 提交到暂存区 git add Index.php # 查看状态 git status ``` `-S, --staged` 取消暂存 ``` git restore --staged Index.php ``` #### 3. 命令总结 --- ``` # 放弃更改 git restore <file1> <file2> # 取消暂存 git restore --staged <file1> <file2> # 所有文件放弃更改 git restore . # 所有文件取消暂存 git restore --staged . ```