mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2025-05-07 05:02:04 +02:00
Extract terminal in its own scene, add a few proper levels with a description
This commit is contained in:
parent
ebbb505283
commit
7373984d47
18 changed files with 179 additions and 92 deletions
levels
01-blob
02-tree
03-commit
04-parents
first
11
levels/01-blob/description
Normal file
11
levels/01-blob/description
Normal file
|
@ -0,0 +1,11 @@
|
|||
At its core, Git is very simple. It stores "objects", which are basically files identified by an "identifier" (short: ID).
|
||||
|
||||
There are four types of objects: blobs, trees, commits, and tags. The simplest type is a "blob", which is just a piece of text.
|
||||
|
||||
Let's create some blobs! To do that, create a file with the desired content, and then use
|
||||
|
||||
$ git hash-object -w <file>
|
||||
|
||||
The flag -w means "write", and tells Git to actually write the new blob to the disk.
|
||||
|
||||
Create three new blobs!
|
21
levels/02-tree/description
Normal file
21
levels/02-tree/description
Normal file
|
@ -0,0 +1,21 @@
|
|||
Blobs just have some content and an ID. It would be convenient to be able to give names to a blob, right?
|
||||
|
||||
The second type of Git object is called a "tree" - a tree points a bunch of blobs, and gives each of them a name!
|
||||
|
||||
How can we build our own trees? Introducing: the index!
|
||||
|
||||
The index is like a "work in progress" version of a tree, where we can add and remove blobs. When we're happy with what we have built, we can make it into a real tree object!
|
||||
|
||||
We can use
|
||||
|
||||
$ git update-index --add <file>
|
||||
|
||||
to make the file's content into a blob, and to add that blob to the index using the file's name.
|
||||
|
||||
When we're happy with out index, we can convert it into a tree using
|
||||
|
||||
$ git write-tree
|
||||
|
||||
That command will output the ID of the newly crated tree.
|
||||
|
||||
Build a tree containing just the 'noises' file, which we conveniently placed in your current directory! :)
|
6
levels/02-tree/goal
Normal file
6
levels/02-tree/goal
Normal file
|
@ -0,0 +1,6 @@
|
|||
echo 'meow' > noises
|
||||
git update-index --add noises
|
||||
git write-tree
|
||||
|
||||
rm noises
|
||||
git update-index --remove noises
|
1
levels/02-tree/start
Normal file
1
levels/02-tree/start
Normal file
|
@ -0,0 +1 @@
|
|||
echo 'meow' > noises
|
9
levels/03-commit/description
Normal file
9
levels/03-commit/description
Normal file
|
@ -0,0 +1,9 @@
|
|||
So a tree describes the state of a directory structure at a specific point in time.
|
||||
|
||||
It would be nice if we could remember when that state existed, and who authored it, right?
|
||||
|
||||
Enter: commits. They are objects that point to a tree and contain some additional metadata. You can create a commit using
|
||||
|
||||
$ git commit-tree <tree> -m "Description of your commit"
|
||||
|
||||
Make a commit from the tree in this repository!
|
7
levels/03-commit/goal
Normal file
7
levels/03-commit/goal
Normal file
|
@ -0,0 +1,7 @@
|
|||
touch empty_file
|
||||
git add .
|
||||
git write-tree
|
||||
git commit-tree 3185 -m 'Clever commit message'
|
||||
|
||||
rm empty_file
|
||||
git update-index --remove empty_file
|
6
levels/03-commit/start
Normal file
6
levels/03-commit/start
Normal file
|
@ -0,0 +1,6 @@
|
|||
touch empty_file
|
||||
git add .
|
||||
git write-tree
|
||||
|
||||
rm empty_file
|
||||
git update-index --remove empty_file
|
5
levels/04-parents/description
Normal file
5
levels/04-parents/description
Normal file
|
@ -0,0 +1,5 @@
|
|||
When using the commit-tree command, you can optionally specify a parent:
|
||||
|
||||
$ git commit-tree <tree> -m "Description" -p <parent commit>
|
||||
|
||||
Can you make a string of three commits? We placed an empty tree in your repo to get you started.
|
2
levels/04-parents/goal
Normal file
2
levels/04-parents/goal
Normal file
|
@ -0,0 +1,2 @@
|
|||
git write-tree
|
||||
git commit-tree 4b82 -m 'We cannot really construct the goal yet :)'
|
1
levels/04-parents/start
Normal file
1
levels/04-parents/start
Normal file
|
@ -0,0 +1 @@
|
|||
git write-tree
|
|
@ -1 +0,0 @@
|
|||
git commit --allow-empty -m "Emtpy commit"
|
|
@ -1,5 +0,0 @@
|
|||
echo -e "bread\ntomato\nbread" > sandwich
|
||||
git add sandwich
|
||||
git commit -m "Initial sandwich"
|
||||
echo -e "bread\ntomato\ncucumber\nbread" > sandwich
|
||||
git commit -am "Add cucumber"
|
Loading…
Add table
Add a link
Reference in a new issue