雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

git restore 放弃更改、取消暂存

2024-09-06 19

1. 前言


git restore 用于恢复工作树文件。应用场景: 取消暂存、放弃更改

2. 使用示例


初始化一个 git 仓库,并且完成一次提交

git initecho Index.php >> Index.phpgit add Index.phpgit 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 .
更新于:12天前
赞一波!

文章评论

全部评论