← Back to Git Course | Chapter 6: Advanced Commands | Lesson 6 of 7

Git archive Command

git archive आपके project की एक clean copy को एक zip box में pack करने जैसा है, history की hidden notebook के बिना, ताकि आप इसे सौंप सकें।
Syntax
bash
git archive [--format=zip] tree_ish -o output_file

Tar Archives में Export करना

git archive किसी specific commit या branch की files को एक single .tar file में bundle करता है, लेकिन — directory की एक plain copy के उलट — इसमें .git/ से कुछ भी शामिल नहीं होता, इसलिए output बिना किसी version history या repository metadata के एक clean snapshot है।

उदाहरण: Exporting to Tar Archives

bash
git archive HEAD -o snapshot.tar

Zip Archives में Export करना

--format=zip pass करना एक tar file के बजाय एक .zip archive produce करता है, जो एक ज़्यादा practical choice है जब आप एक code snapshot किसी ऐसे व्यक्ति को दे रहे हों जिसके पास tar handy न हो या जो terminal में बिल्कुल comfortable न हो, जैसे एक non-technical stakeholder।

उदाहरण: Exporting to Zip Archives

bash
git archive --format=zip HEAD -o snapshot.zip

Specific Directories Archive करना

आपको पूरी repository archive करने की ज़रूरत नहीं — commit reference के बाद एक path append करना (जैसे git archive HEAD -- src/) archive को सिर्फ उस directory तक limit करता है, तब उपयोगी जब सिर्फ एक module को independently share या deploy करना हो।

उदाहरण: Archiving Specific Directories

bash
git archive HEAD -- src/ -o src.tar

Compression Levels Set करना

zip output के लिए, -0 से -9 तक control करते हैं कि archive कितनी जल्दी बनता है और resulting file कितनी छोटी है इसके बीच tradeoff, 0 compression को पूरी तरह skip करते हुए और 9 speed की कीमत पर जितना possible हो उतना compress करते हुए।

उदाहरण: Setting Compression Levels

bash
git archive --format=zip -9 HEAD -o snapshot.zip

Extracted Prefix Directories Add करना

Default रूप से, archive extract करना हर file को सीधे आपकी current directory में dump कर देता है, जो इसे clutter कर सकता है या मौजूदा files overwrite कर सकता है। --prefix=myproject/ archive के अंदर सब कुछ एक named folder में wrap कर देता है, इसलिए इसे extract करना files को loose बिखेरने के बजाय वह folder बनाता है।

उदाहरण: Adding Extracted Prefix Directories

bash
git archive --prefix=myproject/ HEAD -o snapshot.tar
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि git archive में .git folder या uncommitted changes शामिल होंगे, जबकि यह सिर्फ committed files pack करता है।
  2. -o snapshot.zip भूल जाना और archive को terminal पर print होते देखना।
  3. .zip output के लिए --format=zip छोड़ देना, ताकि file का नाम zip हो लेकिन contents tar के हों।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.