Git Object Model (Internals)
In this page:
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
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)
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)
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)
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)
cat .git/refs/heads/main
- यह सोचना कि एक blob file name store करता है, जबकि name tree में store होता है।
.git/objects/के अंदर files को हाथ से edit करना, जो repository corrupt कर देता है।- यह सोचना कि Git versions के बीच diffs store करता है, जबकि हर object एक hash से identified एक snapshot है।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: