mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-15 19:04:57 +01:00
38 lines
1.1 KiB
Text
38 lines
1.1 KiB
Text
|
[description]
|
||
|
|
||
|
Blobs usually represent the content of a file. But on their own, they don't have any metadata, not even a name!
|
||
|
|
||
|
Git has a very powerful concept to store metadata related to blobs: the index! It's a list that relates blobs to filenames and access permissions.
|
||
|
|
||
|
The most convenient option to add an entry to the index is via an existing file:
|
||
|
|
||
|
echo "my content" > file
|
||
|
git update-index --add file
|
||
|
|
||
|
Add three entries to the index! For a bonus challenge: can you add a file that is inside of a directory, like "directory/file"?
|
||
|
|
||
|
[congrats]
|
||
|
|
||
|
There's another way to add an entry to the index directly:
|
||
|
|
||
|
git update-index --add --cacheinfo <mode>,<blobhash>,<name>
|
||
|
|
||
|
The first three numbers of the mode describe the type of the entry, "100" is a regular file.
|
||
|
|
||
|
The second three number describe the permissions. Only "644" (non-executable) and "755" (executable) are supported.
|
||
|
|
||
|
You can insert the hash of an object into the terminal by right-clicking on it! :)
|
||
|
|
||
|
[setup]
|
||
|
|
||
|
[setup goal]
|
||
|
|
||
|
echo "file 1" > file1
|
||
|
echo "file 2" > file2
|
||
|
echo "file 3" > file3
|
||
|
git add .
|
||
|
|
||
|
[win]
|
||
|
|
||
|
test "$(git ls-files | wc -l)" -ge 3
|