article cover image
git level 1
ريادة الأعمال 16 دقيقة 0 تعليق 606 مشاهدة
صورة المستخدم يوشع يوسف
يوشع يوسف
تم النشر 2023-08-21 13:12:56 - آخر تحديث 2023-08-21 13:12:56

ستتعلمه من دون معارف سابقة
لكن حبذا معرفة بسيطة عن واجهة الأوامر النصية للويندوز cmd أو للينوكس bash

يستخدم من أجل مشاريع كودية لكن سنستخدمه من أجل مشاريع أوفيسية

ستخزن مشروعك على سحابة
ستتعاون مع زملائك في المشروع

كن حذر عند تسجيل البيانات

أولا
أنا استخدم
git for windows version 2.39.1.windows.1
نزل تطبيق git
ثبت تطبيق git
افتح git bash إن كنت تعلم أوامر لينوكس أو git cmd إن كنت تعلم أوامر ويندوز هنا ساستخدم bash
لا تستخدم git GUI للإنتاجية

هذا ليس course
هذا استخدم الأداة مباشرة
و لاحظ أن git يساعدك

سأكتب استخدام ثم أضع أمره ثم توضيحات بين " "
أنت أكتب الأمر و لاحظ الاستخدام و توضيحات

اكتب git لمعرفة الأوامر الموجودة

اكتب git --help لرؤية استخدام الأوامر

أكتب إحدى الأوامر مع --hello أو -g ليظهر لك خطأ و ما يتوفر من خيارات للأمر
مثال
git status --hello
git status -g
أو اكتب
git help status
git status --help
man git-status
أو
you can try the #git, #github, or #gitlab channels on the Libera Chat IRC server, which can be found at https://libera.chat/. These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.

اكتب git --version لمعرفة إصدار git

اكتب clear لمسح الشاشة

سنصنع مجلد repository أي مجلد مطبق عليه أوامر git
cd Desktop
"الانتقال إلى سطح المكتب"
mkdir repo
"خلق مجلد ذو اسم repo في سطح المكتب"
cd repo
"الانتقال إلى مجلد ذو اسم repo"
git init
"صنع repo"
Note: The /.git/ directory contains your whole history, do not delete


عند فتح الbash انتقل إلى repo ب
cd ./Desktop/repo

خلق حساب لك في مجلد repo
git config user.name "youshaa yousef"

git config user.email "youshaa010yousef@yahoo.com"

للتأكد من تسجيل الحساب
git config user.name
git config user.email
or
git config --list

"working tree aka local copy الجديد و المعدل
index aka staging area ,tracked انتظار الحفظ"

git status
"show the status of the index and working copy"

Note: “master” is the name of the default branch created by git init

ضع ملفات أو مجلد في مجلد repository
git status
سترى ملفات لم تكن tracked

git status -s
إظهار status بشكل مختصر

ل track ملف أو مجلد (وضعه في index)
git add file_name
"إضافة ملف ذو اسم file_name مع لاحقته(txt او ...) إلى index"
مثال
touch hello.docx
"خلق ملف ذو اسم hello.docx"
git add hello.docx

or
git add .
"إضافة مجلد repo إلى index"

ل unstage
git reset
"إخراج ما أدخلته في index إلى working copy"
git rm --cached file_name
"إخراج الملف ذو اسم file_name في index إلى working copy"
git rm -r --cached dir_name
"إخراج مجلد ذو اسم dir_name في index إلى working copy"

لحذف ما في الindex فورا حتى من ال repo
git reset --hard
or
git rm -f file_name

لإلغاء تعديل ملف
git checkout file_name
or
git restore file_name.

لنرى الاختلافات بين index و working copy للملفات
git diff
لنرى الاختلافات لملف
git diff file_name

لنرى الاختلافات بين ref و ref آخر
git diff ref1 ref2

لنرى الاختلافات بين ref و ref آخر لملف
git diff ref1 ref2 file_name

ref can be a branch_name or a tag_name.

للمقارنة بين الفرع الحالي و فرع آخر
git diff master
لنرى المقارنة مع تغييرات الجديدة
git diff HEAD

git diff --staged
or
git diff --cached
"This command compares your staged changes to your last commit"

run git diff before preparing a commit

لوضع فاصلة زمنية commit مع رسالة و تحفظ التعديلات
git commit -m "message"

in commit messages, describe the rationale behind of your changes (it is often more important than the change itself)

commit as often as you can (keep independent changes in separate commits)

git reset --hard commit
الانتقال إلى commit ما مع إهمال التاليين دون حذفهم لكن يتم تجاهلهم عند الاستمرار ب commitات جديدة

للرجوع إلى فاصلة زمنية ما
git checkout commit_id
و اعتبارها كفرع HEAD

git clean -i -n -f??

حجر تعديل و عزله
git stash
"Save modified and staged changes"
git stash list
"list stack-order of stashed file changes"
فك حجر التعديل
git stash pop
"Apply stored stash content into working directory, and clear stash"
git stash drop
"Delete a specific stash from all your previous stashes."

Tagging known commits
e.g. v2.0.0
git tag
List all tags.
git tag [name] [commit sha] Create a tag reference named name for current commit.Add commit sha to tag a specific commit instead of current one.
git tag -a [name] [commit sha]
Create a tag object named name for current commit.
git tag -d [name]
Remove a tag from local repository

لرؤية commitات
git log --oneline
git log --graph
git log --decorate
git log --pretty=oneline
لا تستخدم git log لتعطيله ال bash

لعرض آخر commit
git show
or
git log -1

git show commit_id

• when was it done ?
• who wrote it ?
• what was changed ?
• why ?
• in which context ?

know who you must blame when something is broken

git log ref

git reflog
"List operations (e.g. checkouts or commits) made on local repository"

git rebase branch_name
"apply any commits of current branch ahead of specified one"

إنشاء فرع
git branch branch_name

تخيل
You may have multiple variants of the same software
• a main branch (where the everyday development happens)
• a maintainance branch (to provide bugfixes in older releases) v1.0.0.#
• a development branch (to make disruptive changes)
• a release branch (to freeze code before a new release) v1.0.0.#
• feature branch v1.0.#.0
• testing branch

git checkout -b branch_name [ starting point ]
· starting point is the starting location of the branch (possibly a commit id, a tag, a branch, . . . ).
If not present, git will use the current location.

حذف فرع
git branch-d branch_name
it cannot delete the current branch (HEAD) or a branch that has not yet been merged into the current branch
حذف فرع فورا
git branch-D branch_name

handle multiple branches concurrently

لدخول فرع
git checkout branch_name
Note: it may fail when the working copy is not clean.

git checkout -b branch_name
Git will create the specified branch if it does not exist.

git checkout -m branch_name
to request merging your local changes into the destination branch.
git switch

تغيير اسم الفرع
git branch --move old new
ما الأفرع؟
git branch branch_name
git branch --all
git branch -a
show all branches with remote

git log branchB..branchA show the commits on branchA that are not on branchB

إضافة فرع إلى الفرع المفتوح مع commitاته
git merge branch_name
git merge origin/master
git mergetool

The result of git merge is immediately committed (unless there is a conflict)

git merge applies only the changes since the last common ancestor in the other branch.
if the branch was already merged previously, then only the changes since the last merge will be merged.

git cherry-pick??
merging a single commit

git gc
garbage collector (run it when the /.git/
directory takes too much space)

git mv file_from file_to
"نقل ملف"
__________________________
كل ما سبق أوفلاين
الآن الأونلاين

هل مجلد repo مربوط ب مجلد السحابة
git remote -v

ربط مجلد repo ب مجلد السحابة
git remote add origin repo_http

رفع محتويات مجلد repo إلى مجلد السحابة
git push -u origin branch_name
share a collection of files with your team

do not forget to run git push

تنزيل محتويات مجلد السحابة إلى مجلد repo
git fetch
ثم دمجها
git merge
أو
pull=git fetch+git merge
git pull origin branch_name
merge changes done by other users

تنزيل مجلد السحابة إلى مجلد repo
git clone link

git clone is a shortcut for the following sequence:
1. git init directory
2. cd directory
3. git remote add origin url
4. git fetch
5. git checkout master

In practice you will rarely use git init, git remote and git fetch directly, but rather use higher-level commands:
git clone and git pull.

تنزيل مجلد من مجلد السحابة إلى مجلد repo
git clone link dir_name

git fetch url branch_name

git fetch [remote]
Fetch changes from the remote, but not update tracking branches.
git fetch --prune [remote]
Delete remote Refs that were removed from the remote repository.
git pull [remote]
Fetch changes from the remote and merge current branch with its upstream.
git push [--tags] [remote]
Push local changes to the remote. Use --tags to push tags.
git push -u [remote] [branch]
Push local branch to remote repository. Set its copy as an upstream.
__________________________
github
إنشاء repository باسم ما
و وصفه ب html سيكون في readme.md

سترى GUI في غيت هاب

دعوة صديق
collaborator

نسخ مشروع شخص ما
fork
و اطلب pull

اختبار المشروع


__________________________
gitlab

__________________________
Hosting only
· GitHub https://github.com/
· BitBucket https://bitbucket.com/
· Google Code https://code.google.com/
· Open source software · Gitlab http://gitlab.org · Gitorious http://gitorious.org

__________________________
تخيل معي
أنك طالب في جامعة و تريد أن تتعاون مع زملائك في شرح المحاضرات لسنوات سابقة إذ كل طالب يختص في مقرر
كل واحد منكم يجب أن يصنع repo و يربطه ب repo على غيت هاب من أجل مقرر اختاره و سيكون سيده
سيكتب المحاضرات و يحددها ب commit و يرفعها ثم اصطفوا في رتل
و كل واحد ينزل المقرر و يعدله و تcommitه باسمه و يرفعه و هكذا بالدور ثم مرحلة التعديل تبادلوا الأدوار للتعديل فلا يستطيع كلا الطالبين تعديل نفس الملف في نفس الوقت

تخيل معي
أنك طالب و لديك مشروع مع زملاءك
هنا يختلف الوضع إن كان مشروع كودي لا أوفيسي
لأن في المحاضرات مهم التعديل لا ال commit لكن في المشروع الكودي مهم ال commitات و الأفرع لضمان وضوح المشروع أي
على كل زميل صنع repo آخر مرافق تجريبي
ينسخ إليه المشروع و يكتب واجبه
و حبذا كثرة ال commitات و عند الانتهاء يعود إلى repo المشروع و يلصق عمله و commitه باسمه و إصدار كن دون حذف repo المرافق التجريبي للعودة إليه عند اللزوم و سيصنع repo آخر من أجل تعديل واجبه لضمان سلامة المشروع

ستتعلمه من دون معارف سابقة
لكن حبذا معرفة بسيطة عن
واجهة الأوامر النصية للويندوز cmd أو
واجهة الأوامر النصية للينوكس bash

يستخدم من أجل مشاريع كودية لكن سنستخدمه من أجل مشاريع أوفيسية

ستخزن مشروعك على الموقع github
ستتعاون مع زملائك في المشروع
ستحفظ إصدارات المشروع
ستنتقل بين مختلف نسخ المشروع

أولا
أنا استخدم
git for windows version 2.41.0.3
نزل تطبيق git
ثبت تطبيق git
افتح git bash إن كنت تعلم أوامر لينوكس أو
افتح git cmd إن كنت تعلم أوامر ويندوز
ساستخدم git bash
بالنسبة ل git GUI لم أجربها

هذا ليس course
هذا استخدم الأداة مباشرة
و لاحظ أن git يساعدك

اكتب git لمعرفة الأوامر الموجودة

اكتب
git status --help
للحصول على مساعدة حول الأمر status أو اكتب
الأمر الخاطئ لترى الصحيح مثال
git status --hlp
press q

اكتب
git --version
لمعرفة إصدار git

اكتب clear لمسح الشاشة

سنصنع مجلد repository
و هو مجلد مطبق عليه أوامر git
اكتب
cd Desktop
"أي الانتقال إلى سطح المكتب"
اكتب
mkdir repo
"أي خلق مجلد ذو اسم repo في سطح المكتب"
اكتب
cd repo
"أي الانتقال إلى مجلد ذو اسم repo"
اكتب
git init
"أي صنع repo أي أصبح المجلد repository"
كامل مشروعك إصداراته محفوظة في ملف .git فلا تحذفه من repo

نغلق git bash
نفتح git bash
اكتب
cd ./Desktop/repo
"أي الانتقال إلى repo"
الاسم بين () هو اسم الفرع الحالي

اكتب
git config user.name "youshaa yousef"
"أي خلق اسم لك في repo"
اكتب
git config user.email "youshaa010yousef@yahoo.com"
"أي خلق بريد إلكتروني لك في repo"


اكتب
git config user.name
git config user.email
"للتأكد إن لديك اسم و ايميل في repo"
or
git config --list

لدينا مصطلح
working tree aka local copy
أي ما خارج .git و داخل repo لكن معدل أو مضاف إلى repo بالنسبة لآخر تعديل ل repo
و لدينا مصطلح
index aka staging area ,tracked
أي ما نريد إدخاله إلى git.

اكتب
git status
لنرى حالة working tree
git status -s
إظهار status بشكل مختصر
git status --short

اكتب
touch file_name.docx
لنخلق ملف

git status
اكتب
git add file_name.docx
ل track ملف أو مجلد موجود في working tree
أي جعله في index

اكتب
git reset
ل unstage
أي للتراجع عن track

اكتب
git rm --cached file_name
ل unstage ملف
اكتب
git rm -r --cached dir_name
ل unstage مجلد

اكتب
git checkout file_name
or
git restore file_name.
للتراجع عن تعديل ملف
لحذفه من working tree

اكتب
git commit -m "message"
ل commit المشروع أي
لوضع فاصلة زمنية commit مع عنوان لها
أي تم إدخال إلى git. و إخلاء working tree و إخلاء index
تذكر الفاصلة الزمنية هي نسخة من المشروع

in commit messages, describe the rationale behind of your changes (it is often more important than the change itself)

اكتب
git commit --amend -m " "
لحفظ التعديلات في commit السابق مع تعديل العنوان

اكتب
git commit --amend --no-edit
ل commit إلى commit الأخير

اكتب
git diff
لنرى التعديلات
اكتب
git diff file_name
لنرى تلك الاختلافات بالنسبة لملف

ref can be a branch_name or a tag_name.

اكتب
git diff ref1 ref2
لنرى الاختلافات بين ref و ref آخر

اكتب
git diff ref1 ref2 file_name
لنرى الاختلافات بين ref و ref آخر لملف

اكتب
git log --oneline
لرؤية commitات

اكتب
git log --graph
لرؤية commitات

اكتب
git log ref
لرؤية commitات ref

اكتب
git show
or
git log -1
لعرض آخر commit

اكتب
git show commit_id
لعرض commit محدد

اكتب
git reset --hard commit_name
الانتقال إلى commit ما

اكتب
git stash
لصنع commit مؤقت ليس commit
git stash list
"list stack-order of stashed file changes"

اكتب
git stash pop
إخلاء commit المؤقت إلى working tree

اكتب
git stash drop
حذف ال commit المؤقت


Tag known commit
e.g. v2.0.0

git tag -a tage.name -m "message" commit_id

git tag -d tag_name
Remove a tag from local repository

عرض tagات
git tag --list
git tag -l
git tag -l --column

عرض tagات مع الرسالة
git tag -n

انتقال إلى commit الموافق ل اسم tag
git reset --hard tag_name
إنشاء فرع
git branch branch_name

حذف فرع
git branch -d branch_name

لدخول فرع
git checkout branch_name

تغيير اسم الفرع
git branch --move old new
git branch -m old new

ما الأفرع؟
git branch
git branch --all
git branch --list

إضافة commitات فرع إلى الفرع الحالي
git merge branch_name
__________________________
كل ما سبق أوفلاين
الآن الأونلاين
افتح
github
اخلق مجلد repo

مجلد السحابة يسمى Remote Repository

اكتب
git remote -v
لمعرفة جواب
هل مجلد repo مربوط ب مجلد github؟

اكتب
git remote add origin repo_http
لربط مجلدك repo ب مجلد github

اكتب
git push -u origin branch_name
لرفع محتويات مجلدك repo إلى مجلد github

اكتب
git clone link
تنزيل مجلد github إلى مجلدك repo

اكتب
git fetch url branch_name
تنزيل فرع في مجلد github إلى مجلدك repo

اكتب
git merge
لدمج ما fetchـه من مجلد github ب مجلدك repo

pull=git fetch+git merge
git pull origin branch_name
_______________________
من خدمات github
1 دعوة صديق
collaborator

2 نسخ مشروع شخص ما
fork
__________________________
تخيل معي
1 مشروع أوفيسي
شرح محاضرات مع فريقك لسنوات سابقة
فحبذا commitات بعدد أعضاء الفريق لأن المهم ما يضيفه العضو لا ما أضاف
2 مشروع كودي
فحبذا كثرة ال commitات و الأفرع لضمان وضوح المشروع

التعليقات (0)