דף כיסום לפקודות Git
Git עוקב אחרי השינויים בקבצים שלך כסדרת קומיטים במאגר. הפקודות האלו מכסות את זרימת העבודה היומיומית: יצירת מאגר, שמירת עבודה, הסתעפות, מיזוג ושיתוף עם מרוחק. השאר את הדף פתוח בזמן הלמידה.
| פקודה | מה היא עושה |
|---|---|
| git init | Create a new, empty Git repository in the current directory. |
| git clone | Download a remote repository and its full history to your machine. |
| git status | Show changed, staged and untracked files in the working tree. |
| git add | Stage changes (files) to be included in the next commit. |
| git commit | Record staged changes as a new commit with a message. |
| git log | Display the commit history of the repository. |
| git diff | Show unstaged or staged differences between states. |
| git branch | List, create or delete branches in the repository. |
| git checkout / switch | Switch branches or restore files (switch is the modern command). |
| git merge | Join another branch's history into the current branch. |
| git rebase | Reapply commits on top of another base commit, rewriting history. |
| git pull | Fetch from a remote and merge the changes into the current branch. |
| git push | Upload local commits to a remote repository. |
| git stash | Temporarily shelve uncommitted changes to reapply later. |
| git remote | Manage the set of remote repositories you track. |
הערות
- רוב הפקודות מקבלות דגלים (כמו -m להודעה או -a לכל); הריצו 'git help <פקודה>' לרשימה המלאה.
- שמות ענפים זולים וניתנים להשלכה — בצעו commit לעתים קרובות בענף תכונה, ואז מיזגו ל-main.
- לפני פקודות הרסניות כמו rebase או reset, ודאו שהעבודה שלכם מקומית (committed) או ב-stash.
שאלות נפוצות
- מה ההבדל בין merge ל-rebase?
- Merge משלב היסטוריות עם קומיט חדש בעל שני הורים. Rebase מנגן מחדש את הקומיטים שלך מעל ענף אחר, ויוצר היסטוריה לינארית אך כותב מחדש את מזהי הקומיט.
- איך מבטלים קומיט?
- השתמש ב-'git revert <commit>' כדי להוסיף קומיט חדש שמבטל את השינוי (בטוח, שומר על ההיסטוריה המשותפת). 'git reset' כותב מחדש את ההיסטוריה ולא אמור לשמש על ענפים משותפים.
- מה ההבדל בין git pull ל-git fetch?
- Fetch מוריד קומיטים ורפרנסים מרחוק מבלי לגעת בעץ העבודה שלך. Pull מבצע fetch ואז ממזג או עושה rebase של השינויים האלה לענף הנוכחי שלך.
- מתי כדאי להשתמש ב-git stash?
- Stash מניח בצד זמנית שינויים שלא קומיטו כדי שתוכל להחליף ענף או למשוך נקי, ואז משחזר אותם ב-'git stash pop'.