git restore 放弃更改、取消暂存
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 .
本站发布的内容若侵犯到您的权益,请邮件联系站长删除,我们将及时处理!
从您进入本站开始,已表示您已同意接受本站【免责声明】中的一切条款!
本站大部分下载资源收集于网络,不保证其完整性以及安全性,请下载后自行研究。
本站资源仅供学习和交流使用,版权归原作者所有,请勿商业运营、违法使用和传播!请在下载后24小时之内自觉删除。
若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,使用者自行承担,概与本站无关。