“git restore <file>”和“git checkout -- <file>”是相同的吗?

4
新命令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
也许这个回答 在Git存储库中查找和恢复已删除的文件 会有所帮助。也可能不会。 - Jonathan Leffler
1
@JonathanLeffler 这个问题是关于命令git restore的。请删除您的评论。 - phd
@phd:不!我为什么要这样做?我指出的答案明确讨论了git restore,即使整个问题并没有(主要是因为在提问时还没有git restore)。 - Jonathan Leffler
1个回答

4

不添加其他选项,是的:

git restore <filename>

并且:

git checkout -- <filename>

如果你在 `git restore` 中添加选项,它们将不再是同义词。你可以在 `git checkout` 中添加选项,也会打破这个配对。虽然有一些额外的模式可以使 `git restore` 和 `git checkout` 同义,但是有一些 `git restore` 操作没有相应的 `git checkout` 命令。例如:
git restore --source HEAD --staged --worktree <filename>

意思与此相同:

git checkout HEAD -- <filename>

但是:

git restore --source HEAD^ <filename>

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接