“ git restore <文件>”是否与“获取结帐-<文件>”相同?

时间:2019-09-09 23:11:20

标签: git

新命令git restore <file>似乎没有太多文档。它和git checkout -- <file>做完全一样的事情吗?

我不理解发行说明中对新命令的解释。

在Git 2.23发行说明中:

  • 引入了两个新命令“ git switch”和“ git restore” 拆分“签出分支机构以推进其历史” “检查出索引以外的路径和/或需要处理的树状路径 单次“ git checkout”中的“前进当前历史记录” 命令。

https://github.com/git/git/blob/master/Documentation/RelNotes/2.23.0.txt

Edit1

https://git-scm.com/docs/git-restore/2.23.0

1 个答案:

答案 0 :(得分:4)

没有其他选项,可以:

git restore <filename>

和:

git checkout -- <filename>

是同义词。

如果您将选项添加到git restore,则不能,它们不再是同义词。您可以向git checkout添加选项,这也会破坏此特定配对。 git restoregit checkout是同义词,但是还有一些git restore操作没有相应的git checkout命令。例如:

git restore --source HEAD --staged --worktree <filename>

与以下内容相同:

git checkout HEAD -- <filename>

但是:

git restore --source HEAD^ <filename>

(将给定文件的HEAD^变体提取到工作树而不触摸索引)无法通过git checkout复制。

相关问题