Отчет по лабораторной работе № 2 "Система контроля версий Git" Выполнил: Чирка А.Р. Группа: А-01-24 Проверил: Козлюк Д. А. Примечание: работа выполнялась на Windows. ------------------------------------------------------------------------- Вход в терминал и создание структуры каталогов ------------------------------------------------------------------------- 1. Создал на рабочем столе каталог lab02 и запустил в нем Git Bash, приглашение: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02 $ 2. Просмотрел файлы в рабочем каталоге можно командой "ls" --- пусто: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02 $ ls 3. Создал каталоги Алисы и Боба, создал каталог "project", изучил команду "cd" в процессе: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02 $ mkdir alice Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02 $ mkdir bob Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02 $ cd alice Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice $ mkdir project Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice $ cd project Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project $ cd .. Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice $ cd project ------------------------------------------------------------------------- Инициализация репозитария и настройка Git ------------------------------------------------------------------------- 4. Инициализировал репозитарий: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project $ git init Initialized empty Git repository in C:/Users/Lenovo/Desktop/lab02/alice/project/.git/ Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ ls -A .git/ 5. Настроим репозитарий Алисы, чтобы коммиты были от ее имени: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git config user.name 'Alice (ChirkaAR)' Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git config user.email 'ChirkaAR@mpei.ru' ------------------------------------------------------------------------- Занесение файлов под контроль версий ------------------------------------------------------------------------- Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git status On branch master //Отображает статус ветки master No commits yet //Еще не было сделано коммитов Untracked files: //Файлы которые не трекаются (use "git add ..." to include in what will be committed) bin/ main.cpp obj/ project.cbp nothing added to commit but untracked files present (use "git add" to track) Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git add main.cpp 6. Еще раз посмотрел состояние рабочей копии Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git status On branch master No commits yet Changes to be committed: //Показывает изменения которые будут закоммичены (use "git rm --cached ..." to unstage) new file: main.cpp Untracked files: (use "git add ..." to include in what will be committed) bin/ obj/ project.cbp 7. Сделал первый коммит Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git commit -m 'code: заготовка программы' [master (root-commit) ea154c7] code: заготовка программы 1 file changed, 9 insertions(+) create mode 100644 main.cpp 8. Поменял имя ветки: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (master) $ git branch -m main ------------------------------------------------------------------------- Составление сообщений к коммитам ------------------------------------------------------------------------- 9. Добавил файл project.cbp в индекс и сделал коммит с ним Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/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 Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git commit -m 'build: add project file' [main 20710a4] build: add project file 1 file changed, 40 insertions(+) create mode 100644 project.cbp Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git status On branch main Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: main.cpp Untracked files: (use "git add ..." to include in what will be committed) bin/ obj/ no changes added to commit (use "git add" and/or "git commit -a") Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git add main.cpp Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git commit -m 'code: add sum' [main a475681] code: add sum 1 file changed, 4 insertions(+), 2 deletions(-) Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git add -u Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git commit -m 'code: add difference' [main b5a62d1] code: add difference 1 file changed, 2 insertions(+), 1 deletion(-) ------------------------------------------------------------------------- Игнорирование файлов ------------------------------------------------------------------------- Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git status On branch main Untracked files: (use "git add ..." to include in what will be committed) .gitignore obj/ project.depend nothing added to commit but untracked files present (use "git add" to track) Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git status On branch main Untracked files: (use "git add ..." to include in what will be committed) .gitignore project.depend nothing added to commit but untracked files present (use "git add" to track) Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git add .gitignore 10. Создал коммит с .gitignore, тема — git. Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git commit -m 'build: git' [main edcde68] build: git 1 file changed, 3 insertions(+) create mode 100644 .gitignore ------------------------------------------------------------------------- Просмотр истории ------------------------------------------------------------------------- Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git log commit edcde6834f3820e782cd531a89b71703a1eb72af (HEAD -> main) Author: Alice (ChirkaAR) Date: Mon Mar 3 00:45:22 2025 +0300 build: git commit b5a62d1b8615bd473334d82364c4ed943447971b Author: Alice (ChirkaAR) Date: Mon Mar 3 00:37:42 2025 +0300 code: add difference commit a4756818091b432fa19a272cda397dba1c5ce95c Author: Alice (ChirkaAR) Date: Mon Mar 3 00:36:30 2025 +0300 code: add sum commit 20710a4a352e308df790462b458ac143ae43ca57 Author: Alice (ChirkaAR) Date: Sun Mar 2 22:59:04 2025 +0300 build: add project file commit ea154c7dcdb92c65b323c1476a0b8ad5e92502ab Author: Alice (ChirkaAR) Date: Sun Mar 2 22:54:27 2025 +0300 code: заготовка программы Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git log --stat commit edcde6834f3820e782cd531a89b71703a1eb72af (HEAD -> main) Author: Alice (ChirkaAR) Date: Mon Mar 3 00:45:22 2025 +0300 build: git .gitignore | 3 +++ 1 file changed, 3 insertions(+) commit b5a62d1b8615bd473334d82364c4ed943447971b Author: Alice (ChirkaAR) Date: Mon Mar 3 00:37:42 2025 +0300 code: add difference main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) commit a4756818091b432fa19a272cda397dba1c5ce95c Author: Alice (ChirkaAR) Date: Mon Mar 3 00:36:30 2025 +0300 code: add sum main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) commit 20710a4a352e308df790462b458ac143ae43ca57 Author: Alice (ChirkaAR) Date: Sun Mar 2 22:59:04 2025 +0300 build: add project file project.cbp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) commit ea154c7dcdb92c65b323c1476a0b8ad5e92502ab Author: Alice (ChirkaAR) Date: Sun Mar 2 22:54:27 2025 +0300 code: заготовка программы main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git log --oneline --decorate edcde68 (HEAD -> main) build: git b5a62d1 code: add difference a475681 code: add sum 20710a4 build: add project file ea154c7 code: заготовка программы Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git log --oneline --decorate --all --graph * edcde68 (HEAD -> main) build: git * b5a62d1 code: add difference * a475681 code: add sum * 20710a4 build: add project file * ea154c7 code: заготовка программы 11. Нашел коммиты по теме build: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git log --grep "build:" commit edcde6834f3820e782cd531a89b71703a1eb72af (HEAD -> main) Author: Alice (ChirkaAR) Date: Mon Mar 3 00:45:22 2025 +0300 build: git commit 20710a4a352e308df790462b458ac143ae43ca57 Author: Alice (ChirkaAR) Date: Sun Mar 2 22:59:04 2025 +0300 build: add project file 12. Нашел коммиты, затрагивающие project.cbp: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git log -- project.cbp commit 20710a4a352e308df790462b458ac143ae43ca57 Author: Alice (ChirkaAR) Date: Sun Mar 2 22:59:04 2025 +0300 build: add project file ------------------------------------------------------------------------- Просмотр коммитов ------------------------------------------------------------------------- 13. Просмотрел предпоследний коммит: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git show HEAD~1 commit b5a62d1b8615bd473334d82364c4ed943447971b Author: Alice (ChirkaAR) Date: Mon Mar 3 00:37:42 2025 +0300 code: add difference diff --git a/main.cpp b/main.cpp index 4364dbc..8435233 100644 --- a/main.cpp +++ b/main.cpp @@ -7,5 +7,6 @@ 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'; } ------------------------------------------------------------------------- Просмотр изменений ------------------------------------------------------------------------- 14. Просмотрел изменения в рабочей копии: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git diff diff --git a/main.cpp b/main.cpp index 8435233..f372c78 100644 --- a/main.cpp +++ b/main.cpp @@ -8,5 +8,6 @@ int main() 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'; } Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git diff HEAD~2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d85abef --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin +/obj +/*.layout diff --git a/main.cpp b/main.cpp index 4364dbc..f372c78 100644 --- a/main.cpp +++ b/main.cpp @@ -7,5 +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' + << "A * B = " << a * b << '\n'; } Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git diff HEAD~2 HEAD diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d85abef --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin +/obj +/*.layout diff --git a/main.cpp b/main.cpp index 4364dbc..8435233 100644 --- a/main.cpp +++ b/main.cpp @@ -7,5 +7,6 @@ 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'; } 15. Просмотрел изменения между самым первым коммитом и коммитом, добавляющим вывод разности: Lenovo@DESKTOP-NEP2E4A MINGW64 ~/Desktop/lab02/alice/project (main) $ git diff ea154c7 b5a62d1 diff --git a/main.cpp b/main.cpp index b4392ec..8435233 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,9 @@ using namespace std; int main() { - cout << "Hello world!" << endl; - return 0; + cout << "Enter A and B: "; + int a, b; + cin >> a >> b; + cout << "A + B = " << a + b << '\n' + << "A - B = " << a - b << '\n'; } diff --git a/project.cbp b/project.cbp new file mode 100644 index 0000000..99bb702 --- /dev/null +++ b/project.cbp @@ -0,0 +1,40 @@ + + + + +