Solution to Step 0 - START

Solution to Step 1 - Show branches

Show which branches exist. Now show the commit graph across all branches.

repo $ git branch -vv

feature-a 9df530e Edited file bar on branch feature-a by bjoern.
* main bcd8ce5 Created file und-tschuess on branch main by bjoern.
some-old-branch 03e1bea : Edit file bar at line 1 on branch main by bjoern.

In the commit graph you can see where the branches and tags are:

repo $ git log --decorate --oneline --graph --all

* 9df530e (feature-a) Edited file bar on branch feature-a by bjoern.
| * bcd8ce5 (HEAD -> main) Created file und-tschuess on branch main by bjoern.
| * ec6319f (tag: release1.1) : Edit file bar at line 5 on branch main by bjoern.
| * 03e1bea (some-old-branch) : Edit file bar at line 1 on branch main by bjoern.
|/
* 95fb57f Edited file hallo-welt on branch main by bjoern.
* 6121b42 (tag: release1.0) Eine Zeile verschieben
* 85f5f20 Noch ein paar neue Zeilen
* 0144fe4 Verschiebe eine Zeile
* 1178ed1 Created file restaurant on branch main by bjoern.
* eaa5d5c Kopiere eine Zeile aus 'bar'
* f9dc882 Erg?nze eine Zeile
* 3592a48 Benenne die Datei im
* 76dd3c1 Erg?nze zwei zeilen
* 5498956 Beginne mit leerer Datei
* e51b518 Created file bar on branch main by bjoern.
* 7b2a390 Created file hallo-welt on branch main by bjoern.

Solution to Step 2 - Switch branch

Switch to the feature-a branch. Look at the content of the bar file in the foo directory. Switch back to main.

repo $ git switch feature-a

Switched to branch 'feature-a'

repo $ cat foo/bar

Jawoll, das ist hier feature-a!

repo $ git switch main

Switched to branch 'main'

Solution to Step 3 - Show tags

Show all tags.

repo $ git tag

release1.0
release1.1

Solution to Step 4 - ⭐ Investigate contents of past versions

Show which files exist in the workspace. Show which files existed in the previous commit. Switch to the previous commit and examine what the workspace looks like then.

Then switch back to main.

These files exist on main:

repo $ ll 

total 16K
drwxr-xr-x 2 vscode vscode 4.0K foo
-rw-r--r-- 1 vscode vscode 12 hallo-welt
-rw-r--r-- 1 vscode vscode 375 nachher
-rw-r--r-- 1 vscode vscode 0 restaurant
-rw-r--r-- 1 vscode vscode 181 und-tschuess

These files existed in HEAD~1:

repo $ git ls-tree HEAD~1

040000 tree c9e9241c3edae05c6f1c858a2170c45052dac10e foo
100644 blob c57eff55ebc0c54973903af5f72bac72762cf4f4 hallo-welt
100644 blob 32b08868b00465cca451251689dda4c9d83b2d85 nachher
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 restaurant

And now we get exactly this version into the workspace:

repo $ git switch --detach HEAD~1

HEAD is now at ec6319f : Edit file bar at line 5 on branch main by bjoern.

repo $ ll 

total 12K
drwxr-xr-x 2 vscode vscode 4.0K foo
-rw-r--r-- 1 vscode vscode 12 hallo-welt
-rw-r--r-- 1 vscode vscode 375 nachher
-rw-r--r-- 1 vscode vscode 0 restaurant

repo $ git switch main

Previous HEAD position was ec6319f : Edit file bar at line 5 on branch main by bjoern.
Switched to branch 'main'

Solution to Step 5 - ⭐ Restore old state of a single file.

The file hallo-welt was edited after release1.0. The customer does not like it. Restore the old state with a new commit.

In release1.0 it looked like this:

repo $ git show release1.0:hallo-welt

Hallo Welt!

Now it looks like this:

repo $ git show HEAD:hallo-welt

Hello World!

Targeted restore:

repo $ git restore -s release1.0 hallo-welt


repo $ git commit -am 'Zurückgeholt'

[main 5349b26] Zur?ckgeholt
1 file changed, 1 insertion(+), 1 deletion(-)

In the commit graph you can see where the branches and tags are:

Now it looks like this again:

repo $ git show HEAD:hallo-welt

Hallo Welt!

To the exercise

To the overview