~ >git init git-playground
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /Users/mchinnappan/git-playground/.git/
~ >cd git-playground
~/git-playground [master] >tree
.
0 directories, 0 files
~/git-playground [master] >tree .git
.git
├── HEAD
├── config
├── description
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── fsmonitor-watchman.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── pre-merge-commit.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ ├── pre-receive.sample
│ ├── prepare-commit-msg.sample
│ ├── push-to-checkout.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
8 directories, 17 files
echo 'Version: 1' > test.txt
git hash-object -w test.txt
f8acaeb421037571491c643e96acc09faea03b24
# Let us the object created by this:
find .git/objects -type f
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
.git/objects/f8/acaeb421037571491c643e96acc09faea03b24 <------
echo 'Version: 2' > test.txt
git hash-object -w test.txt
939ba388fd33e17497577f5cfacd6aa84ef219b9
# Let us the object created by this:
find .git/objects -type f
.git/objects/93/9ba388fd33e17497577f5cfacd6aa84ef219b9 <-----
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
.git/objects/f8/acaeb421037571491c643e96acc09faea03b24
Now you can delete your local copy of that test.txt file, then use Git to retrieve, from the object database, either the first version or second version you saved
rm test.txt
ls -l
git cat-file -p 939ba388fd33e17497577f5cfacd6aa84ef219b9
Version: 2
# Version 1:
git cat-file -p f8acaeb421037571491c643e96acc09faea03b24