GIT:结帐到一个特定的文件夹(GIT: Checkout to a specific folder)

编程入门 行业动态 更新时间:2024-10-11 13:29:13
GIT:结帐到一个特定的文件夹(GIT: Checkout to a specific folder)

我想使用类似的东西:

git checkout -- <path>/<file>

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

任何想法?

I want to use something similar to:

git checkout -- <path>/<file>

but I want to checkout the file to some folder I choose, rather than the overwriting the local <path>/<file>.

Any idea?

最满意答案

根据“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

还从手册页:

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

As per Do a "git export" (like "svn export")?

You can use git checkout-index for that, this is a low level command, if you want to export everything, you can use -a,

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

To quote the man pages:

The final "/" [on the prefix] is important. The exported name is literally just prefixed with the specified string.

If you want to export a certain directory, there are some tricks involved. The command only takes files, not directories. To apply it to directories, use the 'find' command and pipe the output to git.

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

Also from the man pages:

Intuitiveness is not the goal here. Repeatability is.

更多推荐

本文发布于:2023-04-29 09:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   GIT   Checkout   folder   specific

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!