mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +01:00
Polish levels some more, add a "congrats" text
This commit is contained in:
parent
6292d849b9
commit
5066840ae9
30 changed files with 87 additions and 30 deletions
|
@ -1 +0,0 @@
|
||||||
This is an empty level without any winning condition - you can use it as a playground!
|
|
3
levels/basics/congrats
Normal file
3
levels/basics/congrats
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Omnomnom!
|
||||||
|
|
||||||
|
For technical reasons, you can't use `cd` in this prototype yet. But there won't be a lot of interaction with the file system anyways. :)
|
8
levels/basics/description
Normal file
8
levels/basics/description
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
For this prototype, we assume you have some experience with the command line. Here are some commands that will be useful:
|
||||||
|
|
||||||
|
- ls
|
||||||
|
- echo content > file
|
||||||
|
- cat file
|
||||||
|
- mkdir dir
|
||||||
|
|
||||||
|
Find the riddle in your current directory and put the answer into the file "answer"!
|
3
levels/basics/start
Normal file
3
levels/basics/start
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mkdir riddle
|
||||||
|
echo "ppl p" > riddle/consonants
|
||||||
|
echo "ae ie" > riddle/vowels
|
1
levels/basics/win
Normal file
1
levels/basics/win
Normal file
|
@ -0,0 +1 @@
|
||||||
|
cat answer | grep -i "apple \\?pie"
|
3
levels/blob-create/congrats
Normal file
3
levels/blob-create/congrats
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Tip: You can also use a command like this to create a blob in a single line:
|
||||||
|
|
||||||
|
echo "awesome content" | git hash-object -w --stdin
|
|
@ -4,12 +4,8 @@ There are four types of objects: blobs, trees, commits, and tags. The simplest t
|
||||||
|
|
||||||
Let's create some blobs! To do that, create a file with the desired content, and then use
|
Let's create some blobs! To do that, create a file with the desired content, and then use
|
||||||
|
|
||||||
$ git hash-object -w <file>
|
git hash-object -w <file>
|
||||||
|
|
||||||
The flag -w means "write", and tells Git to actually write the new blob to the disk.
|
The flag -w means "write", and tells Git to actually write the new blob to the disk.
|
||||||
|
|
||||||
Create three new blobs!
|
Create three new blobs!
|
||||||
|
|
||||||
Tip: you can also use a command like this to create a blob in a single line:
|
|
||||||
|
|
||||||
$ echo "awesome content" | git hash-object -w --stdin
|
|
||||||
|
|
3
levels/blob-remove/congrats
Normal file
3
levels/blob-remove/congrats
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Generally, `git prune` will be useful if you want to clean up some objects you made.
|
||||||
|
|
||||||
|
Alternatively, you can also click the "Reload" button to restart a level.
|
|
@ -1,5 +1,5 @@
|
||||||
There's a simple command to remove all blobs that are not connected to anything:
|
There's a simple command to remove all objects that are not referenced by anything:
|
||||||
|
|
||||||
$ git prune
|
git prune
|
||||||
|
|
||||||
Remove all blobs in this repository.
|
Remove all blobs in this repository.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
So a tree describes the state of a directory structure at a specific point in time.
|
So a tree describes 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?
|
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
|
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"
|
git commit-tree <tree> -m "Description of your commit"
|
||||||
|
|
||||||
Make a commit from the tree in this repository!
|
Make a commit from the tree in this repository!
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
When using the commit-tree command, you can optionally specify a parent:
|
When using the commit-tree command, you can optionally specify a parent:
|
||||||
|
|
||||||
$ git commit-tree <tree> -m "Description" -p <parent commit>
|
git commit-tree <tree> -m "Description" -p <parent commit>
|
||||||
|
|
||||||
Make a string of three commits!
|
Make a string of three commits!
|
||||||
|
|
||||||
Hint: What would be the easiest way to get a tree object?
|
Hint: You'll need a tree object. What could be the easiest way to obtain one?
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
(This is not a real puzzle yet.)
|
||||||
|
|
||||||
Try merging the two branches together!
|
Try merging the two branches together!
|
||||||
|
|
||||||
git merge <otherbranch>
|
git merge <otherbranch>
|
||||||
|
|
5
levels/conflict/goal
Normal file
5
levels/conflict/goal
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
git merge alternative
|
||||||
|
echo blue-green > bikeshed_color
|
||||||
|
git add .
|
||||||
|
git commit -m "Merge"
|
||||||
|
git prune
|
7
levels/index-add/congrats
Normal file
7
levels/index-add/congrats
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
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.
|
|
@ -1,10 +1,10 @@
|
||||||
Blobs usually represent the content of a file. But on their own, they don't have any metadata, not even a name!
|
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 permissions.
|
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.
|
||||||
|
|
||||||
Even though it is possible to add an entry directly to the index, it's much more convenient to do it via an existing file:
|
The most convenient option to add an entry to the index is via an existing file:
|
||||||
|
|
||||||
$ echo "my content" > file
|
echo "my content" > file
|
||||||
$ git update-index --add 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"?
|
Add three entries to the index! For a bonus challenge: can you add a file that is inside of a directory, like "directory/file"?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
To remove an entry from the index, use a command like this:
|
To remove an entry from the index, use a command like this:
|
||||||
|
|
||||||
$ git update-index --force-remove <file>
|
git update-index --force-remove <file>
|
||||||
|
|
||||||
Remove all entries from the index!
|
Remove all entries from the index!
|
||||||
|
|
|
@ -2,7 +2,7 @@ Instead of removing an entry from the index and adding one with the same name, y
|
||||||
|
|
||||||
Put the content you want in a file with a matching name, and then run
|
Put the content you want in a file with a matching name, and then run
|
||||||
|
|
||||||
$ git update-index <file>
|
git update-index <file>
|
||||||
|
|
||||||
This will create a new blob, and update the hash of the entry to that blob.
|
This will create a new blob, and update the hash of the entry to that blob.
|
||||||
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
test "$(git ls-files | wc -l)" -eq 0
|
# This is not really a good test for the winning condition...
|
||||||
|
test "$(git ls-files -s | git hash-object --stdin)" != "10c4b28623e7e44e09f5a596450a50ab7ac31fbe" -a "$(git ls-files | wc -l)" -eq 3
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
Construct a chain of three trees.
|
Construct a chain of three trees, which don't point to anything else.
|
||||||
|
|
||||||
This is hard! The `git mktree` command might be useful.
|
This is hard! The `git mktree` command might be useful.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
test "$(git show-ref -s | uniq)" = "c7863f72467ed8dd44f4b8ffdb8b57ca7d91dc9e"
|
test "$(git show-ref -s | sort -u)" = "c7863f72467ed8dd44f4b8ffdb8b57ca7d91dc9e"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
To delete a ref, use
|
And finally, to delete a ref, use
|
||||||
|
|
||||||
git update-ref -d refs/<refname>
|
git update-ref -d refs/<refname>
|
||||||
|
|
||||||
Delete all refs! :P
|
Delete all refs! :P (Well, except for HEAD. HEAD is special.)
|
||||||
|
|
13
levels/symref-no-deref/congrats
Normal file
13
levels/symref-no-deref/congrats
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Whew, we've covered a lot of things: Blobs! The index! Trees! Commits! Refs!
|
||||||
|
|
||||||
|
You now know about almost everything about how Git repositories look like on the inside! We think that's pretty cool! :)
|
||||||
|
|
||||||
|
Everything else is just convention and high-level commands that make interacting with the objects more convenient.
|
||||||
|
|
||||||
|
We haven't covered:
|
||||||
|
|
||||||
|
- tag objects (they are the fourth object type - a bit like refs with a description and an author)
|
||||||
|
- configuration (allows you to specify remote repositories, for example)
|
||||||
|
- working with local files (which is, uh, arguably pretty important :P)
|
||||||
|
|
||||||
|
Thanks for playing! You're welcome to check out the "puzzle" levels in the dropdown, some of them are more advanced!
|
3
levels/tree-create/congrats
Normal file
3
levels/tree-create/congrats
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Nice!
|
||||||
|
|
||||||
|
Can you make a different tree? Modify the index, then call `git write-tree` again!
|
|
@ -2,6 +2,6 @@ After carefully building the index we want, it would be nice to save a permanent
|
||||||
|
|
||||||
This is what the second type of objects is for: trees! You can convert the index into a tree using
|
This is what the second type of objects is for: trees! You can convert the index into a tree using
|
||||||
|
|
||||||
$ git write-tree
|
git write-tree
|
||||||
|
|
||||||
Try it! :)
|
Try it! :)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
As soon as you have some tree objects, you can always read them and set the index exactly to their content! Unsurprisingly, the command is called
|
As soon as you have some tree objects, you can always read them and set the index exactly to their content! Unsurprisingly, the command is called
|
||||||
|
|
||||||
$ git read-tree <tree>
|
git read-tree <tree>
|
||||||
|
|
||||||
Try switching between the trees in this repository!
|
Try reading some of the trees in this repository into the index!
|
||||||
|
|
7
levels/welcome/congrats
Normal file
7
levels/welcome/congrats
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Well done!
|
||||||
|
|
||||||
|
An empty Git repository is... well, quite empty. The only thing that always exists is a reference called "HEAD" - we'll learn what that is later!
|
||||||
|
|
||||||
|
But first, let's look at some basics!
|
||||||
|
|
||||||
|
(Click "Next Level" as soon as you're ready!)
|
|
@ -1,7 +1,7 @@
|
||||||
To the left, you see an empty Git repository!
|
This is prototype #1 for the Git learning game by @bleeptrack and @blinry. Thanks for checking it out! <3
|
||||||
|
|
||||||
The only thing that's always there is the HEAD reference - we'll look at what that is later.
|
You can interact with the repository on the right by typing Bash commands in the terminal below!
|
||||||
|
|
||||||
You can drag and drop all nodes on the left, and reorder them how you want!
|
Let's get started by initializing an empty Git repository in the current directory by typing:
|
||||||
|
|
||||||
You can enter Bash commands in the line at the bottom.
|
git init
|
||||||
|
|
1
levels/welcome/goal
Normal file
1
levels/welcome/goal
Normal file
|
@ -0,0 +1 @@
|
||||||
|
git init
|
1
levels/welcome/start
Normal file
1
levels/welcome/start
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rm -rf .git
|
1
levels/welcome/win
Normal file
1
levels/welcome/win
Normal file
|
@ -0,0 +1 @@
|
||||||
|
test -d .git
|
Loading…
Reference in a new issue