开发者

How do I get the effect of GNU tar's --strip-components with git-archive?

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.


Archive that directory as the CWD and you won't have the extra path component:

(cd gitweb; git archive --prefix=git-gitweb/ master .) | tar tf -

Or use this syntax as suggested by the git-archive man page:

git archive --prefix=git-gitweb/ master:gitweb | tar tf -
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜