从广义上讲,我想要的是直接 tar 到 tar 的转换,其中结果的根仅包含原始文件的特定目录子树。
为了举例说明,假设我只想要 gitweb 目录。运行
$ git archive --prefix=git-gitweb/ master gitweb | tar tf -
给出
git-gitweb/
git-gitweb/gitweb/
git-gitweb/gitweb/INSTALL
git-gitweb/gitweb/Makefile
git-gitweb/gitweb/README
git-gitweb/gitweb/gitweb.perl
git-gitweb/gitweb/static/
git-gitweb/gitweb/static/git-favicon.png
git-gitweb/gitweb/static/git-logo.png
git-gitweb/gitweb/static/gitweb.css
git-gitweb/gitweb/static/gitweb.js
,但我想要
git-gitweb/
git-gitweb/INSTALL
git-gitweb/Makefile
git-gitweb/...
手册 提供额外的后端特定选项,但尝试传递 --strip-components
会产生错误:
$ git archive --prefix=git-gitweb/ --strip-components=1 master gitweb | \
tar tf -
error: unknown option `strip-components=1'
usage: git archive [options] [...] ...
无论如何,tar 后端都不是 GNU tar。
freenode 的 #gnu 频道中有人建议 Tardy,但它不理解 git-archive:
$ git archive master > old.tar
$ tardy old.tar new.tar
tardy: old.tar: file type ``g'' unknown
是的,我可以提取 git-archive 的输出使用 --strip-components
并创建结果的新存档,但我试图避免使用文件系统作为临时变量。
In broad terms, what I'd like is a direct tar-to-tar transformation where the result's root contains only a particular directory-subtree of the original.
To illustrate with an example, say I want only the gitweb directory from git's repository. Running
$ git archive --prefix=git-gitweb/ master gitweb | tar tf -
gives
git-gitweb/
git-gitweb/gitweb/
git-gitweb/gitweb/INSTALL
git-gitweb/gitweb/Makefile
git-gitweb/gitweb/README
git-gitweb/gitweb/gitweb.perl
git-gitweb/gitweb/static/
git-gitweb/gitweb/static/git-favicon.png
git-gitweb/gitweb/static/git-logo.png
git-gitweb/gitweb/static/gitweb.css
git-gitweb/gitweb/static/gitweb.js
but I want
git-gitweb/
git-gitweb/INSTALL
git-gitweb/Makefile
git-gitweb/...
The manual provides for extra backend-specific options, but attempting to pass --strip-components
produces an error:
$ git archive --prefix=git-gitweb/ --strip-components=1 master gitweb | \
tar tf -
error: unknown option `strip-components=1'
usage: git archive [options] [...] ...
The tar backend isn't GNU tar anyway.
Someone in freenode's #gnu channel suggested Tardy, but it doesn't understand the output of git-archive:
$ git archive master > old.tar
$ tardy old.tar new.tar
tardy: old.tar: file type ``g'' unknown
Yes, I could extract the output of git-archive with --strip-components
and create a new archive of the result, but I'm trying to avoid using the filesystem as a temporary variable.
发布评论
评论(1)
将该目录存档为 CWD,您将不会有额外的路径组件:
或者使用 git-archive 手册页建议的语法:
Archive that directory as the CWD and you won't have the extra path component:
Or use this syntax as suggested by the
git-archive
man page: