← Back to Git Course | Chapter 10: Tools & Internals | Lesson 4 of 8

Git Object Model (Internals)

अंदर से, Git एक विशाल filing cabinet जैसा है जहाँ हर item को अपने contents से बना एक unique label मिलता है। Files, folders और commits सब इसी तरह store होते हैं।
Syntax
bash
git hash-object -w file_name
git cat-file -p object_hash

.git Folder Internals

Behind the scenes, Git एक simple, content-addressable key-value database है। सभी project files, histories, और commits .git/objects directory के अंदर compressed files की तरह store होते हैं, उनके SHA-1 hashes से identified।

उदाहरण: The .git Folder Internals

bash
ls .git/objects/

Blobs (File Content)

एक blob (binary large object) सिर्फ raw file contents store करता है। यह filename, directory path, या modification date data store नहीं करता। अगर दो files में identical contents हों, वे same blob share करती हैं।

उदाहरण: Blobs (File Content)

bash
git hash-object -w file.txt
git cat-file -p a1b2c3d

Trees (Directories)

एक tree एक directory listing का Git का representation है: हर entry के लिए यह एक name, एक mode (file बनाम directory), और या तो एक blob (एक file) या दूसरी tree (एक subdirectory) की SHA-1 record करता है — nested trees वह तरीका है जिससे Git एक पूरी directory structure को hashes की एक chain की तरह represent करता है।

उदाहरण: Trees (Directories)

bash
git cat-file -p HEAD^{tree}

Commits (Snapshots)

एक commit object directly file contents store नहीं करता — यह उस moment पर पूरे project की state represent करने वाली एक tree hash की ओर point करता है, एक या ज़्यादा parent commit hashes record करता है (merge के लिए एक से ज़्यादा), और author, committer, timestamp, और message carry करता है।

उदाहरण: Commits (Snapshots)

bash
git cat-file -p HEAD

References (Refs)

एक ref एक 40-character commit hash रखने वाली एक छोटी text file के अलावा कुछ नहीं है — main branch के लिए .git/refs/heads/main, एक tag के लिए .git/refs/tags/v1.0। commit करते समय एक branch का "आगे move होना" असल में बस वह एक file है जो एक नए hash से overwrite हो रही है।

उदाहरण: References (Refs)

bash
cat .git/refs/heads/main
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. यह सोचना कि एक blob file name store करता है, जबकि name tree में store होता है।
  2. .git/objects/ के अंदर files को हाथ से edit करना, जो repository corrupt कर देता है।
  3. यह सोचना कि Git versions के बीच diffs store करता है, जबकि हर object एक hash से identified एक snapshot है।

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.