|
| 1 | +# Exercises - Traversing the commit tree |
| 2 | + |
| 3 | +In order to do these exercises, you need to download the exercises zip file. You can do that either by cloning the repository or by just getting the zip file with `wget`. |
| 4 | + |
| 5 | +- Do ONE of the following: |
| 6 | + - **git clone** |
| 7 | + 1. ``git clone https://github.com/hpc2n/course-intro-git.git`` |
| 8 | + 2. ``cd course-intro-git`` |
| 9 | + 3. ``unzip git_materials.zip`` |
| 10 | + 4. ``cd git_materials`` |
| 11 | + 5. ``cd 4.commits`` |
| 12 | + - **Fetch with wget** |
| 13 | + 1. ``wget https://github.com/hpc2n/course-intro-git/raw/refs/heads/main/git_materials.zip`` |
| 14 | + 2. ``unzip git_materials.zip`` |
| 15 | + 3. ``cd git_materials`` |
| 16 | + 4. ``cd 4.commits`` |
| 17 | + |
| 18 | +You are now in a directory with 7 subdirectories, one for each exercise. |
| 19 | + |
| 20 | +## 1. Investigating the commit history |
| 21 | + |
| 22 | +!!! note |
| 23 | + |
| 24 | + The goal of this exercise is to learn to use the `git log` command. |
| 25 | + |
| 26 | +Found under `git_materials/4.commits/1.log` there is a directory named `repository`. Enter it and perform the following steps: |
| 27 | + |
| 28 | +1. Investigate the history. How many commit does the `main` branch contain? |
| 29 | +2. Can you make the output of the command cleaner? |
| 30 | +3. Are there any other branches? How many? What are they called? |
| 31 | +4. Try to filter the output so that only commits that contain the word "abandon" in the commit message are shown. |
| 32 | +5. Does the reference log contain anything interesting? Can you see where the `HEAD` was 6 steps ago? |
| 33 | + |
| 34 | +!!! hint "Hints for this exercise" |
| 35 | + |
| 36 | + - oneline |
| 37 | + - graph |
| 38 | + - reflog |
| 39 | + |
| 40 | +## 2. Recovering the HEAD |
| 41 | + |
| 42 | +!!! note |
| 43 | + |
| 44 | + The goal of this exercise is to learn to identify a "detached HEAD" situation and recover from it. |
| 45 | + |
| 46 | +Enter the `repository/` directory under `git_materials/4.commits/2.recover_head` and perform the following steps: |
| 47 | + |
| 48 | +1. Enter the `repository/` directory and check whether the HEAD is detached. |
| 49 | +2. If the HEAD is detached, return the `HEAD` back to the tip of the branch. |
| 50 | +3. Confirm that that the `HEAD` indeed points to the tip of the branch` |
| 51 | + |
| 52 | +!!! tip "Hints for this exercise" |
| 53 | + |
| 54 | + - git checkout <ref> |
| 55 | + - rev-parse |
| 56 | + - cat .git/something |
| 57 | + |
0 commit comments