Git archive Command
In this page:
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
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
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
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
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
git archive --prefix=myproject/ HEAD -o snapshot.tar
- यह उम्मीद करना कि
git archiveमें.gitfolder या uncommitted changes शामिल होंगे, जबकि यह सिर्फ committed files pack करता है। -o snapshot.zipभूल जाना और archive को terminal पर print होते देखना।.zipoutput के लिए--format=zipछोड़ देना, ताकि file का नाम zip हो लेकिन contents tar के हों।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: