Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
|
1 год назад | |
---|---|---|
.gitignore | 1 год назад | |
README.txt | 1 год назад | |
main.cpp | 1 год назад | |
project.cbp | 1 год назад |
README.txt
Отчёт по лабораторной работе №2. "Система контроля версий Git"
Выполнила: Кузьменко Е.А.
Группа: А-02-23
Проверил:
Примечание: работа выполнялась на Windows.
1.Создала на рабочем столе каталог lab2 и запустила Git Bash, открылось приглашение вида:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2
$
2.В ходе работы будем имитировать проект с двумя участниками: Алисой и Бобом.
Компьютеры Алисы и Боба имитируют папки:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2
$ mkdir alice
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2
$ mkdir bob
Тем самым создала два каталога alice и bob.
3.Далее, я перешла в каталог alice:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2
$ cd alice
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice
$
4.Затем в этом каталоге создала папку project и перешла в неё:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice
$ mkdir project
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice
$ cd project
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project
$
4.1.С помощью команды cd .. я перешла на уровень выше, а после вернулась обратно в каталог project:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project
$ cd ..
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice
$ cd project
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project
$
5.Инициализирую репозиторий в текущем каталоге(теперь GIT следит за всеми папками и файлами, что здесь находятся):
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project
$ git init
Initialized empty Git repository in C:/Users/Admin/Desktop/lab2/alice/project/.git/
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$
Появилась ветка master(по умолчанию), в дальнейшем я поменяю её на main(после первого коммита).
6.Настроила репозиторий Алисы, чтобы коммиты были от ее имени:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git config user.name 'Alice(KuzmenkoEA)'
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git config user.email 'KuzmenkoYA@mpei.ru'
7.Запускаю CodeBlocks и создаю проект в репозитории Алисы.
/Desktop/lab2/alice/project/project.cbp
Возвращаюсь в Git Blash, просматриваю состояние рабочей копии:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed) \\ Показывает неотслеживаемые файлы в каталоге project
bin/
main.cpp
obj/
project.cbp
nothing added to commit but untracked files present (use "git add" to track)
8.Занесём файл main.cpp под Git, то есть начнём отслеживать файл.
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git add main.cpp
9.Проверила состояние ещё раз, можно заметить, как пропал main.cpp:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: main.cpp \\ Появился отслеживаемый файл, с которым можно выполнять коммиты
Untracked files:
(use "git add <file>..." to include in what will be committed)
bin/
obj/
project.cbp
10.Выполнила коммит с файлом main.cpp и коротким сообщением:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git commit -m 'code: preparation of the program'
[master (root-commit) 1642893] code: preparation of the program
1 file changed, 9 insertions(+)
create mode 100644 main.cpp
11.После создания первого коммита меняю имя ветки на main:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (master)
$ git branch -m main
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main) //Изменилась ветка
$
12.Занесла файл project.cbp под GIT и выполнила с ним коммит:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add project.cbp
warning: in the working copy of 'project.cbp', LF will be replaced by CRLF the next time Git touches it
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'build: added a file project'
[main dd98c9c] build: added a file project
1 file changed, 40 insertions(+)
create mode 100644 project.cbp
13.В CodeBlocks заменила тело функции main() на ввод двух чисел:
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
return 0;
}
14.Проверим состояние копии, когда мы внесли изменения:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: main.cpp //Изменения в файле
Untracked files:
(use "git add <file>..." to include in what will be committed)
bin/
obj/
no changes added to commit (use "git add" and/or "git commit -a")
Можно заметит, что после изменения "new file: main.cpp" изменился на "modified: main.cpp", то есть в файле произошли доработки.
15.1.Закоммитим изменения на примере нахождения суммы a и b. Заменила тело функции на нахождение суммы:
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A + B =" << a + b << '\n';
return 0;
}
15.2.Сначала выбрала файл, изменения которых должны войти в коммит, затем сделала коммит(1 способ):
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'code: add sum'
[main 409a5e9] code: add sum
1 file changed, 4 insertions(+), 1 deletion(-)
16.1.Закоммитим изменения на примере нахождения разности a и b. Заменила тело функции на нахождение разности:
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A + B = " << a + b << '\n'
<< "A - B = " << a - b << '\n';
return 0;
}
16.2.Добавила в индекс все изменения, затем сделала коммит(2 способ):
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add -u
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'code: add dif'
[main 814aee8] code: add dif
1 file changed, 2 insertions(+), 1 deletion(-)
17.Можно заметить, что в выводе команды git status все время присутствуют каталоги bin/ и obj/:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git status
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
bin/
obj/
nothing added to commit but untracked files present (use "git add" to track)
Указала Git игнорировать присутствие каталогов bin и obj.
Для этого в CodeBlocks создала новый файл под названием ".gitignore" (File → New... → Empty) и записала в него строки:
/bin
/obj
После этого шага проверила статус:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git status
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
project.depend
nothing added to commit but untracked files present (use "git add" to track)
Каталоги пропали, то есть они занесены в список игнорируемых.
18.Внесла .gitignore в GIT. Создала коммит:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add .gitignore
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'git: ignor'
[main 01cb623] git: ignor
1 file changed, 2 insertions(+)
create mode 100644 .gitignore
19.Работа с журналом репозитория. Просмотрела все коммиты по теме build:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git log --grep "build:"
commit dd98c9c1c9da2bc34db09e8bc10dc929c4e79354
Author: Alice(KuzmenkoEA) <KuzmenkoYA@mpei.ru>
Date: Sun Apr 7 20:52:08 2024 +0300
build: added a file project
Просмотрела все коммиты, затрагивающие project.cbp:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git log -- project.cbp
commit dd98c9c1c9da2bc34db09e8bc10dc929c4e79354
Author: Alice(KuzmenkoEA) <KuzmenkoYA@mpei.ru>
Date: Sun Apr 7 20:52:08 2024 +0300
build: added a file project
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git show 814aee8
commit 814aee835047c9092e8aa347373299a6203029e6
Author: Alice(KuzmenkoEA) <KuzmenkoYA@mpei.ru>
Date: Sun Apr 7 21:11:12 2024 +0300
code: add dif
diff --git a/main.cpp b/main.cpp
index 103c153..cc5dfbf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,6 +7,7 @@ int main()
cout << "Enter A and B";
int a, b;
cin >> a >> b;
- cout << "A + B =" << a + b << '\n';
+ cout << "A + B = " << a + b << '\n'
+ << "A - B = " << a - b << '\n';
return 0;
}
20.Просмотрела препоследний коммит тремя способами:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git show HEAD~1
commit 814aee835047c9092e8aa347373299a6203029e6
Author: Alice(KuzmenkoEA) <KuzmenkoYA@mpei.ru>
Date: Sun Apr 7 21:11:12 2024 +0300
code: add dif
diff --git a/main.cpp b/main.cpp
index 103c153..cc5dfbf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,6 +7,7 @@ int main()
cout << "Enter A and B";
int a, b;
cin >> a >> b;
- cout << "A + B =" << a + b << '\n';
+ cout << "A + B = " << a + b << '\n'
+ << "A - B = " << a - b << '\n';
return 0;
}
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git show main~1
commit 814aee835047c9092e8aa347373299a6203029e6
Author: Alice(KuzmenkoEA) <KuzmenkoYA@mpei.ru>
Date: Sun Apr 7 21:11:12 2024 +0300
code: add dif
diff --git a/main.cpp b/main.cpp
index 103c153..cc5dfbf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,6 +7,7 @@ int main()
cout << "Enter A and B";
int a, b;
cin >> a >> b;
- cout << "A + B =" << a + b << '\n';
+ cout << "A + B = " << a + b << '\n'
+ << "A - B = " << a - b << '\n';
return 0;
}
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git show 814aee8
commit 814aee835047c9092e8aa347373299a6203029e6
Author: Alice(KuzmenkoEA) <KuzmenkoYA@mpei.ru>
Date: Sun Apr 7 21:11:12 2024 +0300
code: add dif
diff --git a/main.cpp b/main.cpp
index 103c153..cc5dfbf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,6 +7,7 @@ int main()
cout << "Enter A and B";
int a, b;
cin >> a >> b;
- cout << "A + B =" << a + b << '\n';
+ cout << "A + B = " << a + b << '\n'
+ << "A - B = " << a - b << '\n';
return 0;
}
21.Измению тело фукнции main() на вывод произведения:
int main()
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A * B = " << a * b << '\n';
return 0;
}
Выполню коммит изменения в рабочей копии:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'code: add pro'
[main d2345e4] code: add pro
1 file changed, 1 insertion(+), 2 deletions(-)
Вернулась к предыдущему коммиту(отменила текущий)
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git reset --hard HEAD~1
HEAD is now at 01cb623 git: ignor
В CodeBlocks видны изменения: текст программы вернулся к тому состоянию, в котором он был:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A + B = " << a + b << '\n'
<< "A - B = " << a - b << '\n';
return 0;
}
22.Добавила над функцией main() комментарий:
// you may type whatever you want
Уберала эти изменения в main.cpp, откатив этот файл к состоянию в последнем коммите (HEAD):
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git checkout HEAD -- main.cpp
23.Далее, я зарегистрировалась на Git УИТ под именем KuzmenkoEA.
В Git создала пару ключей: ssh-keygen
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/Admin/.ssh/id_ed25519):
Created directory '/c/Users/Admin/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Admin/.ssh/id_ed25519
Your public key has been saved in /c/Users/Admin/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:5k9Hb6u0N7DjjrGML3YFYC/r+ZKl99z1A8QnVeFQCtQ Admin@DESKTOP-GFU1N7D
The key's randomart image is:
+--[ED25519 256]--+
| .o...o+|
| o .E+. |
| . o .... |
| . o + . |
| So .o o |
| o. ..oo |
| ..=o.oo+ .|
| O=oBo+o+.|
| ..BB+B+o.o|
+----[SHA256]-----+
Запустила агент:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ eval $(ssh-agent -s)
Agent pid 499
Загрузила ключ:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ ssh-add
Enter passphrase for /c/Users/Admin/.ssh/id_ed25519:
Identity added: /c/Users/Admin/.ssh/id_ed25519 (Admin@DESKTOP-GFU1N7D)
Отобразила открытый ключ:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOCbGQz2gj0mbzUaeQPc4ptAcnxjaSt9cJ1pgcdN6kEk Admin@DESKTOP-GFU1N7D
Перешла в Git УИТ и добавила открытый ключ в список открытых ключей своей учетной записи.
24.Создала новый репозиторый(Git УИТ) cs-lab02.
После создания пустого репозитория пишу команды, чтобы связать локальный репозиторый с удалённым:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git remote add origin http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git push -u origin main
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcm/autodetect for more information.
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcm/autodetect for more information.
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 2 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (15/15), 1.90 KiB | 74.00 KiB/s, done.
Total 15 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
25.Открываю новый терминал в каталоге bob. Получаю проект с сервера:
$ git clone http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git project
Cloning into 'project'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 15 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (15/15), done.
Resolving deltas: 100% (1/1), done.
Теперь в каталоге bob появился project, в котором склонированны все файлы с сервера.
Перешла в каталог project:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob
$ cd project
26.Настроила репозиторий Боба, чтобы коммиты были от его имени:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git config user.name 'Bob(KuzmenkoEA)'
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git config user.email 'KuzmenkoYA@mpei.ru'
27.В CodeBlocks меняю тело функции main()(bob -> project) на вывод произведения:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A * B = " << a * b << '\n';
return 0;
Добавляю коммит:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git commit -m 'code: add pro'
[main 43e5097] code: add pro
1 file changed, 1 insertion(+), 2 deletions(-)
И отправляю коммит на сервер:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git push
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcm/autodetect for more information.
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcm/autodetect for more information.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 385 bytes | 128.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
01cb623..43e5097 main -> main
28.В каталоге alice/project выполнила загрузку изменений:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 365 bytes | 4.00 KiB/s, done.
From http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02
01cb623..43e5097 main -> origin/main
29.Посомтрела историю всех веток:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git log --oneline --decorate --all --graph
* 43e5097 (origin/main) code: add pro
* 01cb623 (HEAD -> main) git: ignor
* 814aee8 code: add dif
* 409a5e9 code: add sum
* dd98c9c build: added a file project
* 1642893 code: preparation of the program
Подвинула ветку к скачанной версии:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git pull --ff-only
Updating 01cb623..43e5097
Fast-forward
main.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
30.Изменила тело функции main() на вывод деления чисел:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A / B = " << a / b << '\n';
return 0;
}
Выполнила коммит:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'code: add div'
[main 82a5b92] code: add div
1 file changed, 1 insertion(+), 1 deletion(-)
Отправила коммит на сервер:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git push
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcm/autodetect for more information.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 385 bytes | 128.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
43e5097..82a5b92 main -> main
31.В терминале bob получила новую версию:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 365 bytes | 1024 bytes/s, done.
From http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02
43e5097..82a5b92 main -> origin/main
32.В теле функции main()(каталога alice) изменим:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
int a, b;
cin >> a >> b;
cout << "A + B = " << a + b << '\n'
<< "A - B = " << a - b << '\n'
<< "A * B = " << a * b << '\n'
<< "A / B = " << a / b << '\n';
return 0;
}
Добавим коммит:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'code: add sumdifprodiv'
[main 4e9d4a7] code: add sumdifprodiv
1 file changed, 4 insertions(+), 1 deletion(-)
33.Изменим тело функции main() (каталог alice) на нахождение максимума:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
int a, b, maxa;
cin >> a >> b;
maxa = a + b;
if((a - b) > maxa) maxa = a - b;
if((a * b) > maxa) maxa = a * b;
if((a / b) > maxa) maxa = a / b;
cout << "Max = " << maxa;
return 0;
}
Создадим коммит:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git commit -m 'code: add max'
[main ad472c7] code: add max
1 file changed, 6 insertions(+), 5 deletions(-)
И отправим его на сервер:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git push
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 2 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 929 bytes | 132.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
82a5b92..ad472c7 main -> main
34.То же самое проделаем в терминале bob:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git commit -m 'code: add max'
[main 77877c2] code: add max
1 file changed, 6 insertions(+), 2 deletions(-)
Попытка отправить на сервер:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git push
To http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Переместим коммит Боба поверх коммита Алисы, то есть поверх origin/main:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git rebase origin/main
Auto-merging main.cpp
CONFLICT (content): Merge conflict in main.cpp
error: could not apply 77877c2... code: add max
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 77877c2... code: add max
35.В CodeBlocks Боба появились места конфликта:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
int a, b, maxa;
cin >> a >> b;
<<<<<<< HEAD
cout << "A / B = " << a / b << '\n';
=======
maxa = a + b;
if((a - b) > maxa) maxa = a - b;
if((a * b) > maxa) maxa = a * b;
if((a / b) > maxa) maxa = a / b;
cout << "Max = " << maxa;
>>>>>>> 77877c2 (code: add max)
return 0;
}
После правок и разрешения конфликта добавим файл в индекс и продолжим прерванную операцию:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main|REBASE 1/1)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main|REBASE 1/1)
$ git rebase --continue
[detached HEAD 6230af8] code: add max
1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/main.
Снова отправим на сервер(в этот раз без ошибки):
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/bob/project (main)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 386 bytes | 96.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://uit.mpei.ru/git/KuzmenkoEA/cs-lab02.git
ad472c7..6230af8 main -> main
36.В каталоге alice создадим ветку double:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git branch double
Переключимся на неё:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git checkout double
Switched to branch 'double'
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (double)
$
В теле функции Заменим тип переменных a и b на double и сделаем коммит:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter A and B";
double a, b;
int maxa;
cin >> a >> b;
maxa = a + b;
if((a - b) > maxa) maxa = a - b;
if((a * b) > maxa) maxa = a * b;
if((a / b) > maxa) maxa = a / b;
cout << "Max = " << maxa;
return 0;
}
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (double)
$ git add main.cpp
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (double)
$ git commit -m 'code: switch double'
[double 89eae77] code: switch double
1 file changed, 2 insertions(+), 1 deletion(-)
Вернёмся на ветку main:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (double)
$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$
Соединим ветки double и main(double в main):
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git merge double
Updating ad472c7..89eae77
Fast-forward
main.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
37.Просмотр всех веток:
Admin@DESKTOP-GFU1N7D MINGW64 ~/Desktop/lab2/alice/project (main)
$ git log --oneline --decorate --all --graph
* 89eae77 (HEAD -> main, double) code: switch double
* ad472c7 (origin/main) code: add max
* 4e9d4a7 code: add sumdifprodiv
* 82a5b92 code: add div
* 43e5097 code: add pro
* 01cb623 git: ignor
* 814aee8 code: add dif
* 409a5e9 code: add sum
* dd98c9c build: added a file project
* 1642893 code: preparation of the program
Создадим коммит README и отправим на сервер.