هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
الهدف
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.
قبل أن تبدأ
- Make a new folder:
mkdir ~/git-lab2 && cd ~/git-lab2 && git init -b main. - The "app" is
check.sh: it must printOKand exit 0.
المهام
ضع علامة على المهمة عندما تنتهي منها. متصفحك فقط يتذكر ذلك.
- Make 20 commits with a loop. In every commit,
check.shprintsOK; only in commit 13 the line becomesecho FAIL; exit 1, and that stays until the end. Tag the first commitv1.0(annotated). - Start
git bisectwith the newest commit as bad andv1.0as good. Let Git test every step withgit bisect run ./check.sh. - Write down the commit Git found, then end bisect.
- Show who changed the line with
git blame, and find the commit withgit log -S "FAIL". - Before you fix it, change
notes.txt(unfinished work). Park it withgit stash push -m, check that the tree is clean. - Fix
check.sh, commit, and make the annotated tagv1.1with a message. - Bring your stashed work back and show the stash list is empty.
تحقّق من عملك
./check.shprintsOKandexit=0.git tag -nshowsv1.0andv1.1with their messages.git stash listis empty andgit status --shortshowsM notes.txt(your work is back).- Bisect found the commit with the message
change 13.
تلميحات
اعرض التلميحات
- A loop:
for i in $(seq 1 20); do ...; git commit -qam "change $i"; done. git bisect start BAD GOOD;git bisect run CMDmarks each step good (exit 0) or bad (exit 1–127 except 125).git bisect resetbrings you back tomain.git log -S "text" --onelinelists commits that add or remove the text.git tag -a v1.1 -m "message";git stash popbrings work back and deletes the stash entry.
الحل
اعرض الحل
- 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 - Let Git search.
- Read the result.
<hash> is the first bad commit change 13git bisect reset - Who changed it, and when.
- Park the unfinished work.
- Hotfix and release tag.
- Get the work back.
The last command needs a remote; tags are not pushed by a normal
git push.
ملاحظاتي
لا توجد ملاحظات بعد.