git restore 放弃更改、取消暂存
2024-09-06
19
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. 命令总结
更新于:12天前# 放弃更改
git restore <file1> <file2>
# 取消暂存
git restore --staged <file1> <file2>
# 所有文件放弃更改
git restore .
# 所有文件取消暂存
git restore --staged .
赞一波!
相关文章
- Git 行尾设置须知
- git 原理初探
- git remote 命令详解
- git diff 命令详解
- git reset 回退版本(版本穿梭)
- git log 命令
- git branch 命令详解
- git 设置记住密码和清除密码
- 宝塔利用 Git + WebHook 实现与码云同步【自动部署】
- Git 的 GUI 图形界面管理工具
- git pull 从远程获取代码并合并本地的版本
- git config 配置提交人信息(用户名和邮箱)
- Git出现两条重复的提交记录
- Git正确的提交代码流程
- Git rebase是什么意思?
- Git里rebase和merge的区别?
- request merge和squash merge的区别
- Git rebase和merge的区别?
- 具有预提交功能的 Git Hook 管理
- Linux必备的Git图形化工具
文章评论
全部评论