سناریو اول
- فرض کنید یک مخزن (مثلا با نام projectX) موجود است. (قبلا ساخته شده است.)
- فرض کنید این مخزن فاقد هرگونه فایل و … است.
- فرض کنید بر روی پروژهی مورد نظر کار کردید و حالا میخواهید این پروژه را درون این مخزن قرار دهید.
- برای این منظور :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
root@homayouni:~# mkdir /tmp/test/ root@homayouni:~# cd /tmp/test/ root@homayouni:/tmp/test# git config --global user.name "iman homayouni" root@homayouni:/tmp/test# git config --global user.email "homayouni.iman@gmail.com" root@homayouni:/tmp/test# <span style="color: #ff0000;">git clone git@gitlab.example.com:iman/projectX.git</span> Cloning into 'projectX'... warning: You appear to have cloned an empty repository. root@homayouni:/tmp/test# cd projectX root@homayouni:/tmp/test/projectX# cp -ra /root/projectX/* . root@homayouni:/tmp/test/projectX# <span style="color: #ff0000;">git add *</span> root@homayouni:/tmp/test/projectX# <span style="color: #ff0000;">git commit -m "add All Files to repo"</span> [master (root-commit) bbfaa78] add All Files to repo 1 file changed, 4 insertions(+) create mode 100755 scriptX.sh root@homayouni:/tmp/test/projectX# <span style="color: #ff0000;">git push -u origin master</span> Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 254 bytes | 254.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To gitlab.example.com:iman/projectX.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'. |
سناریو دوم
- فرض کنید یک سورس کد در اختیار دارید که آمادهی استفاده است.
- فرض کنید مخزنی با نام پروژه ندارید و میخواهید سورس پروژه را داخل مخزن قرار دهید. (یعنی مخزنی نیز با نام پروژه ساخته شود.)
- برای این منظور ابتدا وارد دایکتوری پروژه شوید :
|
1 |
root@homayouni:~# cd /root/projectI/ |
- دستور زیر را اجرا کنید :
|
1 |
root@homayouni:~/projectI# <span style="color: #ff0000;">git init</span> |
- یک مخزن با نام projectI ایجاد نمایید.
|
1 |
root@homayouni:~/projectI# <span style="color: #ff0000;">git remote add origin git@gitlab.example.com:iman/<strong>projectI</strong>.git</span> |
- تمام پروندهها و دایکتوریها را add نمایید.
|
1 |
root@homayouni:~/projectI# <span style="color: #ff0000;">git add .</span> |
- یک کامیت برای تمامی پروندههایی که add کردید، در نظر بگیرید.
|
1 2 3 4 |
root@homayouni:~/projectI# <span style="color: #ff0000;">git commit -m "Initial commit"</span> [master (root-commit) 238b2f0] Initial commit 1 file changed, 1 insertion(+) create mode 100644 projectI.txt |
- در نهایت داخل مخزن projectI و شاخهی master آپلود (push) نمایید.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
root@homayouni:~/projectI# <span style="color: #ff0000;">git push -u origin master</span> Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 226 bytes | 113.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: remote: The private project iman/projectI was successfully created. remote: remote: To configure the remote, run: remote: git remote add origin git@gitlab.example.com:iman/projectI.git remote: remote: To view the project, visit: remote: http://gitlab.example.com/iman/projectI remote: remote: remote: To gitlab.example.com:iman/projectI.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'. |
سناریو سوم
- فرض کنید یک مخزن با نام ProjectX موجود است.
- سورس داخل این مخزن درون شاخهی master قرار گرفته و در حال stable است. یعنی سورس برنامه بدون مشکل کار میکند.
- حال فرض کنید قصد گرفتن سورس را دارید تا بر روی آن کار کنید و یک سری قابلیت به آن اضافه کنید.
- برای این منظور ابتدا یک clone از آن دریافت نمایید :
|
1 2 3 4 5 6 7 8 9 |
root@homayouni:~# <span style="color: #ff0000;">git clone http://gitlab.example.com/iman/projectx.git</span> Cloning into 'projectx'... Username for 'http://gitlab.example.com': iman Password for 'http://iman@gitlab.example.com': remote: Enumerating objects: 8, done. remote: Counting objects: 100% (8/8), done. remote: Compressing objects: 100% (5/5), done. remote: Total 8 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (8/8), 632 bytes | 70.00 KiB/s, done. |
- یک شاخه با نام unstable ایجاد میکنیم.
|
1 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git branch unstable</span> |
- برای مشاهدهی شاخههای موجود :
|
1 2 3 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git branch</span> * <span style="color: #99cc00;">master</span> unstable |
- برای تغییر شاخهی از master به unstable :
|
1 2 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git checkout unstable</span> Switched to branch 'unstable' |
- حال بر روی سورس کار کنید.
- حال پروندهها را Add کنید.
|
1 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git add *</span> |
- برای آن یک کامیت در نظر بگیرید.
|
1 2 3 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git commit -m 'changing main source'</span> [unstable 18de532] changing main source 2 files changed, 2 insertions(+), 17 deletions(-) |
- در نهایت داخل شاخهی unstable پوش نمایید :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git push origin unstable</span> Username for 'http://gitlab.example.com': iman Password for 'http://iman@gitlab.example.com': Enumerating objects: 9, done. Counting objects: 100% (9/9), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (5/5), 529 bytes | 132.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) remote: remote: To create a merge request for unstable, visit: remote: http://gitlab.example.com/iman/projectx/-/merge_requests/new?merge_request%5Bsource_branch%5D=unstable remote: To http://gitlab.example.com/iman/projectx.git * [new branch] unstable -> unstable |
- حال برای دیدن سورس stable کافیست که شاخه را عوض کنید.
|
1 2 3 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git checkout master</span> Switched to branch 'master' Your branch is up to date with 'origin/master'. |
- حال داخل ورژن stable سورس هستید ! میتوانید دوباره به ورژن unstable سورس برگردید.
|
1 2 |
root@homayouni:~/projectx# <span style="color: #ff0000;">git checkout unstable</span> Switched to branch 'unstable' |