ورقة غش لأوامر 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 <أمر>' للقائمة الكاملة.
- أسماء الفروع رخيصة وقابلة للإهمال — التزم كثيرًا في فرع ميزة ثم ادمج في main.
- قبل الأوامر التدميرية مثل rebase أو reset، تأكد من أن عملك ملتزم به أو محفوظ في stash.
الأسئلة الشائعة
- ما الفرق بين merge وrebase؟
- يجمع merge التواريخ عبر التزام جديد له أبوان. أمّا rebase فيعيد تشغيل التزاماتك فوق فرع آخر، منتجًا تاريخًا خطيًا لكنه يعيد كتابة معرّفات الالتزام.
- كيف أتراجع عن التزام؟
- استخدم 'git revert <commit>' لإضافة التزام جديد يلغي التغيير (آمن، يحفظ التاريخ المشترك). أما 'git reset' فيعيد كتابة التاريخ ولا يجب استخدامه على الفروع المشتركة.
- ما الفرق بين git pull وgit fetch؟
- يجلب fetch الالتزامات والمراجع من مستودع بعيد دون المساس بشجرة العمل. أمّا pull فيجلب ثم يدمج أو يعيد ترتيب تلك التغييرات في فرعك الحالي.
- متى أستخدم git stash؟
- يضع stash التغييرات غير الملتزمة جانبًا مؤقتًا لتتمكن من تبديل الفروع أو السحب بوضوح، ثم تستعيدها لاحقًا بـ 'git stash pop'.