CodeBlanks Logo Icon CodeBlanks

zip and tar

Learn to create archives in zip and tar formats.

Supported Formats

Git natively supports tar and zip archive formats. You can run git archive --list to see all supported formats.

$ git archive --list
tar
tgz
tar.gz
zip

To explicitly specify the format, use the --format=zip or --format=tar option.

--format and Extension Inference

Git automatically infers the format from the file extension when you pass -o file.zip or -o file.tar. However, when piping to standard output, the --format flag must be specified explicitly.

git archive --format=tar HEAD | gzip > paket.tar.gz
git archive --format=zip -o dagitim.zip HEAD

This allows you to build pipelines with compression tools for custom compression steps.

Practice Archive with Format Specification

Archive the HEAD commit in the repository using the --format=tar and --output=paket.tar options. Then print the contents with tar -tf paket.tar.

Starter code

terminal
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "console.log('calisiyor');" > index.js
git add index.js
git commit -q -m "Uygulama kodu"

# Formati ve ciktisi belirtilen arsivi olustur ve listele:

Sample solution

terminal
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "console.log('calisiyor');" > index.js
git add index.js
git commit -q -m "Uygulama kodu"

git archive --format=tar --output=paket.tar HEAD
tar -tf paket.tar

Expected output

index.js

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command is used to list archive formats supported by Git in the terminal?

  • git archive --show-types
  • git config --get archive
  • git archive --formats-all
  • git archive --list Correct answer

Explanation: The `git archive --list` command outputs formats supported by Git on the system, such as tar and zip.

2 Specify Zip Format

Question
git archive --format=____ -o paket.zip HEAD
Answer
git archive --format=zip -o paket.zip HEAD

Explanation: The `--format=zip` parameter is provided for the zip archive format.

3 Formats and Options

Term Meaning
--list Lists supported formats
--format=tar Produces standard tar archive
--format=zip Produces compressed zip archive
-o paket.zip Infers zip format from extension

All lessons in Advanced