נבנה על ידיBuilt by Ariel Yohimovich

PythonPython
20
חלקPart 3: קוד נקי ו-OOPClean code & OOP כ-3 שעות (כולל הפסקה)About 3 hours (with a break)

Git ו-GitHubGit & GitHub

commit, branch, merge, push ו-README טוב.

commit, branch, merge, push and a good README.

או Ctrl+Por Ctrl+P

הנקודות החשובותKey points

  • final_v2_REAL.py זה לא שיטהfinal_v2_REAL.py is not a system
  • היסטוריה מלאה, חזרה לכל נקודהFull history, return to any point
  • git init יוצר מאגרgit init creates a repo
  • git add → אזור ההכנה (staging)git add → staging area
  • git diff: מה השתנה ועדיין לא נשמרgit diff: what changed and isn't saved yet
  • git log --oneline: רשימת ה-commitsgit log --oneline: the list of commits
  • לא שומרים .venv/ ו-__pycache__/Don't save .venv/ and __pycache__/
  • לעולם לא סיסמאות ומפתחותNever passwords and keys
  • git switch -c feature יוצר ענף ועובר אליוgit switch -c feature creates a branch and moves to it

מונחיםTerms

  • GitGit: תוכנה ששומרת את כל ההיסטוריה של הקוד: מי שינה מה ומתי, ומאפשרת לחזור לכל גרסה.Software that keeps the whole history of your code: who changed what and when, and lets you go back to any version.
  • מאגר (repository)repository: תיקיית פרויקט ש-Git עוקב אחריה (יש בה תיקייה נסתרת .git). בקיצור: repo.A project folder Git tracks (it has a hidden .git folder). Short: repo.
  • commitcommit: תמונת מצב שמורה של הקבצים, עם הודעה שמסבירה מה השתנה ומזהה ייחודי (hash).A saved snapshot of the files, with a message explaining what changed and a unique id (hash).
  • אזור ההכנה (staging)staging area: המקום שבו מכינים מה ייכנס ל-commit הבא. git add מכניס לשם קבצים.Where you prepare what goes into the next commit. git add puts files there.
  • ענף (branch)branch: קו פיתוח נפרד: אפשר לנסות רעיון בענף בלי לגעת בקוד הראשי, ואחר כך למזג.A separate line of work: try an idea on a branch without touching the main code, then merge.
  • מיזוג (merge)merge: איחוד השינויים מענף אחד לענף אחר.Combining the changes from one branch into another.
  • GitHubGitHub: אתר שמאחסן מאגרי Git ברשת: גיבוי, שיתוף, ועבודה משותפת. ה-repo שם נקרא remote.A website that hosts Git repositories online: backup, sharing and collaboration. The repo there is called a remote.
  • .gitignore.gitignore: קובץ שמפרט אילו קבצים Git לא יעקוב אחריהם, כמו .venv/ וסיסמאות.A file listing what Git should not track, like .venv/ and passwords.

Cheatsheet

.gitignore.gitignore
.venv/
__pycache__/
*.pyc
.env
shelf.db

שגיאות שפגשנוErrors we met

שגיאהErrorמה זה אומרWhat it meansמה עושיםWhat to do
AssertionErrorמוסיפים לקוד מפתח סודי, וכך הוא נשמר בהיסטוריה לתמיד.Putting a secret key in the code, so it's saved in history forever.AssertionError: a secret is written in the code: ...: שומרים סודות בקובץ .env שמופיע ב-.gitignore, וקוראים אותם עם os.environ. נראה איך במפגש 33.AssertionError: a secret is written in the code: ...: keep secrets in a .env file listed in .gitignore and read them with os.environ. We'll see how in session 33.

נבנה על ידיBuilt by Ariel Yohimovich