Git — הכנה וסדר עבודה בסיסי
מה Git עושה בפרויקט כמו TRIDENT, ואיפה מריצים אותו
Section titled “מה Git עושה בפרויקט כמו TRIDENT, ואיפה מריצים אותו”בפרויקט יש כמה repos נפרדים, וכל אחד נכתב על ידי גורם אחר:
| repo | מי כותב | מי קורא |
|---|---|---|
trident-source | אתה (קוד, Dockerfile, בדיקות) | ה-runner (CI) |
trident-ci | אתה (YAML של ה-pipeline + promote.sh) | include מתוך source |
trident-gitops | אתה (values, Applications) וגם ה-CI (קובץ versions/<ENV>.yaml) | Argo CD |
trident-templates | אתה (charts) | Argo CD |
שלושה עותקים של כל repo: העותק ב-GitLab (האמת), העותק של Argo (קורא משם בלבד), והעותק המקומי שלך (נעשה ישן מהר). push שלא קרה = לא קיים בשביל Argo.
ביום המבחן סביר שהכול קורה על ה-VM עצמה: git, kubectl ו-helm באותו shell. תכין שם זהות ו-SSH key (ראה ssh) ולא תסתמך על Mac.
5 הדקות הראשונות על VM חדשה
Section titled “5 הדקות הראשונות על VM חדשה”git config --global user.name "<USER>"git config --global user.email "<EMAIL>"git config --global pull.ff onlymkdir -p -m 700 ~/.sshssh-keygen -t ed25519 -f ~/.ssh/exam_key -C "exam-vm" -N ""cat ~/.ssh/exam_key.pubהדבק את ה-.pub ב-GitLab (Avatar ← Edit profile ← SSH Keys), ואז:
ssh -F /dev/null -i ~/.ssh/exam_key -o IdentitiesOnly=yes -T git@<GITLAB_HOST>printf 'Host <GITLAB_HOST>\n User git\n IdentityFile ~/.ssh/exam_key\n IdentitiesOnly yes\n' >> ~/.ssh/configchmod 600 ~/.ssh/configgit clone git@<GITLAB_HOST>:<GROUP>/<REPO>.gitחזור על ה-clone לכל repo. הסבר ופתרון תקלות: ssh.
איך מוודאים: Welcome to GitLab, @<USER>!, ו-git -C <REPO> log --oneline -1 מראה commit.
להגדיר זהות פעם אחת (user.name / user.email)
Section titled “להגדיר זהות פעם אחת (user.name / user.email)”בלי זהות git commit נכשל או חותם בשם לא רצוי. ההגדרה נשמרת ב-~/.gitconfig.
git config --global user.name "<USER>"git config --global user.email "student@example.com"git config --global init.defaultBranch maingit config --global pull.ff onlypull.ff only גורם ל-git pull להיכשל בקול במקום ליצור merge commit מיותר (ראה sync).
איך מוודאים: git config --global --list מציג את ארבע השורות.
לשכפל repo (clone) מ-GitLab
Section titled “לשכפל repo (clone) מ-GitLab”השתמש ב-path של ה-group, לא בשם התצוגה. הכתובת המדויקת: ב-GitLab לחץ Code ← Clone with SSH.
git clone git@<GITLAB_HOST>:<GROUP>/<REPO>.git# TRIDENT: git clone git@gitlab.com:trident-lab00/trident-gitops.gitcd <REPO>איך מוודאים: git remote -v מציג את אותה כתובת פעמיים (fetch ו-push), ו-git log --oneline -3 מראה commits.
למשוך branch ספציפי כבר בשלב ה-clone (--single-branch מוריד רק אותו):
git clone -b <BRANCH> --single-branch git@<GITLAB_HOST>:<GROUP>/<REPO>.gitלראות איפה אני: status, branch, remotes
Section titled “לראות איפה אני: status, branch, remotes”git status -sbgit branch --show-currentgit remote -vgit branch -vvgit status -sb נותן שורה ראשונה כמו ## main...origin/main [behind 1] ואחריה קבצים ששונו. git branch -vv מראה לכל branch מול איזה remote branch הוא עוקב ואם הוא ahead/behind.
| פלט | משמעות |
|---|---|
לשנות כתובת של remote: git remote set-url origin <URL>, ואז git remote -v לאימות. |
| M file | שונה, לא ב-staging |
| M file | שונה וב-staging (יכנס ל-commit) |
| ?? file | קובץ חדש שגיט לא עוקב אחריו |
| [ahead 1] | יש commit מקומי שלא נדחף |
| [behind 1] | יש commit ב-remote שלא משכת |
לשמור שינוי: add, commit, push
Section titled “לשמור שינוי: add, commit, push”git add <FILE>git commit -m "describe the change"git pushgit add -A מוסיף הכול (כולל קבצי זבל). עדיף קבצים בשמם, או git add -p כדי לבחור חלקים. git commit -am "msg" מדלג על add, אבל רק לקבצים שכבר במעקב.
איך מוודאים: git status -sb ללא ahead, ו-git log --oneline -1 מראה את ההודעה. ב-GitLab ה-commit מופיע ב-repo.
לראות מה השתנה: log ו-diff
Section titled “לראות מה השתנה: log ו-diff”git log --oneline --graph --decorate --all -15git diffgit diff --stagedgit diff origin/main..HEADgit show <SHA> --statgit log -p -- <FILE>| פקודה | מראה |
|---|---|
git diff | שינויים שעוד לא ב-staging |
git diff --staged | מה ייכנס ל-commit הבא |
git diff origin/main..HEAD | מה ה-commits שלך מוסיפים מעל origin/main (אחרי fetch) |
git log --oneline HEAD..origin/main | commits שיש ב-remote ואין אצלך |
git show <SHA> --stat | commit אחד: הודעה + קבצים |
מי שינה קובץ לאחרונה (למשל versions/dev.yaml)
Section titled “מי שינה קובץ לאחרונה (למשל versions/dev.yaml)”git fetchgit log origin/main -1 --format='%h %an %ad %s' -- <FILE>git blame -L 1,10 <FILE>שורה ראשונה: ה-commit האחרון שנגע בקובץ (מחבר של בוט ה-CI = promote). blame -L 1,10 מראה לכל שורה בטווח את ה-commit שכתב אותה.
איך מוודאים: ה-<SHA> מה-log מופיע גם ב-git show <SHA> --stat עם הקובץ.
לבדוק מה קרה ל-repo לפני שאני עורך
Section titled “לבדוק מה קרה ל-repo לפני שאני עורך”לפני כל עריכה ב-repo שה-CI כותב אליו (כמו gitops):
git pullgit status -sbאיך מוודאים: ## main...origin/main בלי ahead או behind. אם git pull נכשל, עבור ל-sync.