1
0

More than 1 year has passed since last update.

git archiveと.gitginoreされているがgit管理下にあるファイル

Posted at

結論

git管理下にあればgit archiveに拾われる

実験手順と結果

$mkdir git_archive_test1

$cd git_archive_test1/

$git init
Initialized empty Git repository in /home/yumetodo/git_archive_test1/.git/

$echo "arikitari" > a.txt

$nano Makefile

$cat Makefile
ARCHIVE = test

hash := $(firstword $(shell git ls-remote . HEAD))

$(ARCHIVE).tar.gz: $(ARCHIVE)
tar czf $@ $<

$(ARCHIVE):
        rm -rf $@
        mkdir $@
        git archive $(hash) | tar xf - -C $@
        mv $< $@/$<
        echo $(hash) >$@/COMMIT

$git add .

$git commit -m "init commit"
[main (root-commit) dff4133] init commit
 2 files changed, 14 insertions(+)
 create mode 100644 Makefile
 create mode 100644 a.txt

$echo "a.txt" > .gitignore

$git add .

$git commit -m "ignore"
[main e44f0a5] ignore
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore

$git log --oneline
e44f0a5 (HEAD -> main) ignore
dff4133 init commit

$make
rm -rf test
mkdir test
git archive e44f0a58ff4240a4fe0983e190f7bf7a551baf27 | tar xf - -C test
echo e44f0a58ff4240a4fe0983e190f7bf7a551baf27 >test/COMMIT
tar czf test.tar.gz test

$ls -la
合計 60K
drwxr-xr-x 1 yumetodo なし   0  4月  5 17:38 ./
drwxr-xr-x 1 yumetodo なし   0  4月  5 17:37 ../
drwxr-xr-x 1 yumetodo なし   0  4月  5 17:38 .git/
-rw-r--r-- 1 yumetodo なし   6  4月  5 17:37 .gitignore
-rw-r--r-- 1 yumetodo なし  10  4月  5 17:37 a.txt
-rw-r--r-- 1 yumetodo なし 210  4月  5 17:37 Makefile
drwxr-xr-x 1 yumetodo なし   0  4月  5 17:38 test/
-rw-r--r-- 1 yumetodo なし 450  4月  5 17:38 test.tar.gz

$ls -la test
合計 8.0K
drwxr-xr-x 1 yumetodo なし   0  4月  5 17:38 ./
drwxr-xr-x 1 yumetodo なし   0  4月  5 17:38 ../
-rw-r--r-- 1 yumetodo なし   6  4月  5 17:37 .gitignore
-rw-r--r-- 1 yumetodo なし  10  4月  5 17:37 a.txt
-rw-r--r-- 1 yumetodo なし  41  4月  5 17:38 COMMIT
-rw-r--r-- 1 yumetodo なし 210  4月  5 17:37 Makefile

ignoreしているa.txtが確認できた

考察

git archiveするときには別に.gitignoreは見られていない。

1
0
1

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
1
0