Geavanceerd
Zoeken inLabs
Zo zoek je
  • Zoek een taak of een tool (lvm, selinux, @podman); filter op niveau en op boek of cursus.
  • Met een leeg zoekvak toont een filter alleen al de labs — bijvoorbeeld alle moeilijke labs van één cursus.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Lab 7.1Git, Hoofdstuk 7

Find the bad commit with bisect, park work with stash, release with a tag

Niveau
Gemiddeld
40 min
Machines
any computer with Git 2.30 or newer, Bash
Status
Nog niet begonnen

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Doel

A script worked in version 1 and is broken now, 20 commits later. You build that history with a small loop, then use git bisect run to find the bad commit automatically, git blame and git log -S to see who changed the line, git stash to park unfinished work during the hotfix, and an annotated tag to mark the fixed release.

Voordat je begint

Taken

  1. Make 20 commits with a loop. In every commit, check.sh prints OK; only in commit 13 the line becomes echo FAIL; exit 1, and that stays until the end. Tag the first commit v1.0 (annotated).
  2. Start git bisect with the newest commit as bad and v1.0 as good. Let Git test every step with git bisect run ./check.sh.
  3. Write down the commit Git found, then end bisect.
  4. Show who changed the line with git blame, and find the commit with git log -S "FAIL".
  5. Before you fix it, change notes.txt (unfinished work). Park it with git stash push -m, check that the tree is clean.
  6. Fix check.sh, commit, and make the annotated tag v1.1 with a message.
  7. Bring your stashed work back and show the stash list is empty.

Controleer je werk

./check.sh; echo "exit=$?"
git tag -n
git stash list
git status --short
  • ./check.sh prints OK and exit=0.
  • git tag -n shows v1.0 and v1.1 with their messages.
  • git stash list is empty and git status --short shows M notes.txt (your work is back).
  • Bisect found the commit with the message change 13.

Hints

Toon de hints

Oplossing

Toon de oplossing
  1. Build the history.
    printf '#!/bin/sh\necho OK\n' > check.sh && chmod +x check.sh
    echo "notes" > notes.txt
    git add . && git commit -qm "change 0"
    git tag -a v1.0 -m "First good version"
    for i in $(seq 1 20); do echo "step $i" >> notes.txt; [ "$i" -eq 13 ] && printf '#!/bin/sh\necho FAIL; exit 1\n' > check.sh; git commit -qam "change $i"; done
    ./check.sh; echo $?
    FAIL
    1
  2. Let Git search.
    git bisect start main v1.0
    git bisect run ./check.sh
  3. Read the result.
    <hash> is the first bad commit
        change 13
    git bisect reset
  4. Who changed it, and when.
    git blame check.sh
    git log -S "FAIL" --oneline
  5. Park the unfinished work.
    echo "half-done idea" >> notes.txt
    git stash push -m "wip notes"
    git status --short
  6. Hotfix and release tag.
    printf '#!/bin/sh\necho OK\n' > check.sh
    git commit -qam "Fix check.sh (bug from change 13)"
    git tag -a v1.1 -m "Hotfix: check.sh prints OK again"
  7. Get the work back.
    git stash pop
    git stash list
    git push origin v1.1

    The last command needs a remote; tags are not pushed by a normal git push.

Mijn notities

Nog geen notities.

Lessen voor dit lab

Commando's in dit lab