git reset -- 和 git restore --staged 区别
相同点:
"You can remove the file from the index while keeping your changes with git reset." --From man git-reset
"git reset can also be used to 'restore the index, overlapping with' git restore." --From man git
联系:
"This means that git reset
is the opposite of git add . This command is equivalent to git restore [--source=] --staged ...." --From man git-reset
老版本git会提示
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
新版本git会提示
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
原来是git中的checkout命令承载了分支操作和文件恢复的部分功能,有点复杂,并且难以使用和学习,所以社区解决将这两部分功能拆分开,在git 2.23.0中引入了两个新的命令switch和restore用来取代checkout。From: 知乎
原来git中文件恢复涉及到两个命令,一个是checkout,一个是reset,reset除了重置分支之外,还提供了恢复文件的能力;新的restore命令专门用来恢复staged和worktree的文件。From: 知乎
注意:
git reset -- == git reset HEAD --
Interactively select hunks in the difference between the index and (defaults to HEAD). --From man git-reset
阅读(3673) | 评论(0) | 转发(0) |