如何使用git-archive获取GNU tar的--strip-components的效果?

Gre*_*con 3 unix linux git gnu tar

从广义上讲,我想要的是直接的tar-to-tar转换,其结果的根只包含原始的特定目录子树.

举一个例子来说明,我只想从git的存储库中获取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并创建结果的新存档,但我试图避免使用文件系统作为临时变量.

bst*_*rre 8

将该目录存档为CWD,您将没有额外的路径组件:

(cd gitweb; git archive --prefix=git-gitweb/ master .) | tar tf -
Run Code Online (Sandbox Code Playgroud)

或者使用git-archive手册页建议的语法:

git archive --prefix=git-gitweb/ master:gitweb | tar tf -
Run Code Online (Sandbox Code Playgroud)