GIT:签出到特定的文件夹

我想用类似于:

git checkout -- <path>/<file>

但我想将文件签出到我选择的某个文件夹,而不是覆盖本地/。

任何想法?


按照“git export”(例如“svn export”)?

你可以使用git checkout-index ,这是一个低级命令,如果你想要导出所有东西,你可以使用-a

git checkout-index -a -f --prefix=/destination/path/

引用手册页:

最后的“/”[在前缀上]很重要。 导出的名称实际上只是以指定的字符串作为前缀。

如果您想要导出某个目录,则会涉及一些技巧。 该命令只接收文件,而不是目录。 要将其应用于目录,请使用'find'命令并将输出传递给git。

find dirname -print0 | git checkout-index --prefix=/path-to/dest/ -f -z --stdin

另外从手册页:

直觉性不是这里的目标。 重复性是。


另一个更清洁的解决方案 - 只需指定一个不同的工作树。

要检查从HEAD(非索引)到特定输出目录的所有内容:

git --work-tree=/path/to/outputdir checkout HEAD -- .

要从HEAD中检出子目录或文件到特定目录:

git --work-tree=/path/to/outputdir checkout HEAD -- subdirname

对于单个文件:

git show HEAD:abspath/to/file > file.copy
链接地址: http://www.djcxy.com/p/26263.html

上一篇: GIT: Checkout to a specific folder

下一篇: how to remove git tracking from a project?