使用--work-tree
这迫使您也使用--git-dir
指向您的 .git 目录。
--git-dir=.git
假设您在您的 git 文件夹中。您当然可以通过调整此文件夹从其他任何地方调用此命令。
以下将检出文件到您选择的任何目录。这不包括现有工作树中的任何本地(未提交)更改。它确实包括索引的变化(放在那里git add
)
git --git-dir=.git --work-tree=/folder/into/which/to/export/ restore .
用于--source=HEAD
忽略索引。
git --git-dir=.git --work-tree=/folder/into/which/to/export/ restore --source=HEAD .
或者您可以使用--source
指定您想要的任何提交(分支、标签、哈希)。
git --git-dir=.git --work-tree=/folder/into/which/to/export/ restore --source=my-tag .
你甚至可以限制你的 git repo 中的一些路径
git --git-dir=.git --work-tree=/folder/into/which/to/export/ restore --source=HEAD:path/in/your/repo .
如果您希望在 dest 文件夹中创建部分文件夹结构(用于子路径)
git --git-dir=.git --work-tree=/folder/into/which/to/export/ restore --source=HEAD:path/in/ your/repo
仍然只有出口path/in/your/repo
。但创建目录/folder/into/which/to/export/your/repo
。