LoginSignup
10
7

More than 5 years have passed since last update.

tarでVCS関連のファイルを除外してアーカイブする

Last updated at Posted at 2013-04-23

何気なくmanを見ていてGNU tarに--exclude-vcsなるオプションが有ることを知りました。
VCS関連のファイルを除外してくれるようです。
(まぁ昨今のVCSならexportとかarchiveみたいなサブコマンド使ってもよいんですが。)

たとえば、こんな感じでgitで管理しているディレクトリがあったとして、

foo
├── .git
│   ├── HEAD
│   ├── branches
│   ├── config
│   ├── info
│   │       :(snip)
│   └── refs
├── .gitignore
├── bar.txt
└── foo.txt

アーカイブ時に--exclude-vcsオプションを加えてやると、

$ tar --exclude-vcs -zcf foo.tar.gz foo

このようにVCS関連のファイル/ディレクトリが除外されてアーカイブされます。
(.gitと.gitignoreが除外された)

$ tar -ztf foo.tar.gz
foo/
foo/foo.txt
foo/bar.txt

除外されるパターンは、CentOS6に入ってたv1.23と最新のv1.26共にこのような定義になっていました。

tar.c
static char const * const vcs_file_table[] = {
  /* CVS: */
  "CVS",
  ".cvsignore",
  /* RCS: */
  "RCS",
  /* SCCS: */
  "SCCS",
  /* SVN: */
  ".svn",
  /* git: */
  ".git",
  ".gitignore",
  /* Arch: */
  ".arch-ids",
  "{arch}",
  "=RELEASE-ID",
  "=meta-update",
  "=update",
  /* Bazaar */
  ".bzr",
  ".bzrignore",
  ".bzrtags",
  /* Mercurial */
  ".hg",
  ".hgignore",
  ".hgtags",
  /* darcs */
  "_darcs",
  NULL
};

参考

GNU tar 1.26: 6.4 Excluding Some Files
http://www.gnu.org/software/tar/manual/html_section/exclude.html

10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7