---
# System prepended metadata

title: Лабораторная работа №2

---

# Лабораторная работа №2
## Задание 1
1. Создание локального репозитория
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_1> git init
    Initialized empty Git repository in /home/
    ```

2. Копирование файла `.gitignore` из предыдущей лабораторной работы
    ```bash
    kuznetsovev/opi_labs/lab_02/task_1/.git/
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> cp ../../lab_01/.gitignore .gitignore
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> cat .gitignore
    **/__pycache__/**
    ```

3. Копирование файлов лабораторной работы и помещение из под версионный контроль
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git add *.py .gitignore
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git status
    On branch master

    No commits yet

    Changes to be committed:
      (use "git rm --cached <file>..." to unstage)
        new file:   .gitignore
        new file:   iarray.py
        new file:   main.py
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git commit -m "COPY: work files"
    [master (root-commit) cac9920] COPY: work files
     3 files changed, 46 insertions(+)
     create mode 100644 .gitignore
     create mode 100644 iarray.py
     create mode 100644 main.py
    ```

4. Создание ветки для исправления ошибок
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git branch fix
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git checkout fix
    Switched to branch 'fix'
    kuznetsovev@kuznetsovev ~/o/l/task_1 (fix)> git branch
    * fix
      master
    ```

5. Переключение на ветку `master` и слияние веток
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_1 (fix)> git checkout master
    Switched to branch 'master'
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git merge fix
    Updating cac9920..2fb14fb
    Fast-forward
     iarray.py |  8 +++++++-
     main.py   | 20 ++++++++++++++++++--
     2 files changed, 25 insertions(+), 3 deletions(-)

    ```
    Ошибок при слиянии не было
    
6. `git log --oneline --graph --all`
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_1 (master)> git log --oneline --graph --all
    * 2fb14fb (HEAD -> master, fix) FIX: issue
    * 09bccaa FIX: error show
    * f4be2e4 ADD: test case
    * 2cbe080 ADD: comments
    * cac9920 COPY: work files
    ```
    Ошибок при слиянии не возникло, тк не было конфликтующих изменений
    
## Задание 2
1. Распаковка репозитория
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_2> unzip ~/Desktop/small_fir.zip
    Archive:  /home/kuznetsovev/Desktop/small_fir.zip
    ...
    kuznetsovev@kuznetsovev ~/o/l/task_2> mv small_fir/song.txt song.txt
    kuznetsovev@kuznetsovev ~/o/l/task_2> mv small_fir/.git/ .git/
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master)> rm -rf small_fir/

    ```
2. Анализ репозитория
    1. Всего в репозитории 2 ветви
        ```bash
        kuznetsovev@kuznetsovev ~/o/l/task_2 (master)> git branch -a
          develop
        * master
        ```
        Они называются `master` и `develop`
    2. Над репозиторием работали 2 автора `Minstrel` и `Songster`
    3. В репозитории находится 1 файл `song.txt`. Сначала изменения вносил `Minstrel` в ветке `master`, потом `Songster` в ветке `develop`
3. Слияние ветвей
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master)> git merge develop
    Auto-merging song.txt
    CONFLICT (content): Merge conflict in song.txt
    Automatic merge failed; fix conflicts and then commit the result.
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master|MERGING) [1]> git status
    On branch master
    You have unmerged paths.
      (fix conflicts and run "git commit")
      (use "git merge --abort" to abort the merge)

    Unmerged paths:
      (use "git add <file>..." to mark resolution)
        both modified:   song.txt

    no changes added to commit (use "git add" and/or "git commit -a")
    ```
    Содержание `song.txt` во время слияния
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master|MERGING)> cat song.txt
    <<<<<<< HEAD
    В лесу родилась ёлочка,
    В лесу она росла.
    Зимой и летом стройная,
    Зелёная была.

    Трусишка зайка серенький
    Под ёлочкой скакал.
    Порою волк, сердитый волк,
    Рысцою пробегал.

    Чу! Снег по лесу частому
    Под полозом скрипит.
    Лошадка мохноногая
    Торопится, бежит.
    =======
    Метель ей пела песенку:
    «Спи, ёлочка, бай-бай!»
    Мороз снежком укутывал:
    «Смотри, не замерзай!»

    Везёт лошадка дровенки,
    На дровнях - мужичок
    Срубил он нашу ёлочку
    Под самый корешок.

    Теперь она, нарядная,
    На праздник к нам пришла,
    И много, много радости
    Детишкам принесла.
    >>>>>>> develop
    ```
    Содержание `song.txt` для слияния 
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master|MERGING)> cat song.txt
    В лесу родилась ёлочка,
    В лесу она росла.
    Зимой и летом стройная,
    Зелёная была.

    Трусишка зайка серенький
    Под ёлочкой скакал.
    Порою волк, сердитый волк,
    Рысцою пробегал.

    Чу! Снег по лесу частому
    Под полозом скрипит.
    Лошадка мохноногая
    Торопится, бежит.
    
    Метель ей пела песенку:
    «Спи, ёлочка, бай-бай!»
    Мороз снежком укутывал:
    «Смотри, не замерзай!»

    Везёт лошадка дровенки,
    На дровнях - мужичок
    Срубил он нашу ёлочку
    Под самый корешок.

    Теперь она, нарядная,
    На праздник к нам пришла,
    И много, много радости
    Детишкам принесла.
    ```
    Закрепление слияния
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master|MERGING)> git status
    On branch master
    All conflicts fixed but you are still merging.
      (use "git commit" to conclude merge)

    Changes to be committed:
        modified:   song.txt

    kuznetsovev@kuznetsovev ~/o/l/task_2 (master|MERGING)> git commit -m "Merge song.txt"
    [master d716670] Merge song.txt
    kuznetsovev@kuznetsovev ~/o/l/task_2 (master)> git status
    On branch master
    nothing to commit, working tree clean
    ```
## Задание 3
### Задание 3.1
[Merge request](https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/4)
### Задание 3.2
1. Получение копии репозитория
    ```bash
    kuznetsovev@kuznetsovev ~/o/lab_02> git clone gitlab@git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
    Cloning into 'iu7-software-engineering-labs-2022-kuznetsovegor'...
    remote: Enumerating objects: 25, done.
    remote: Counting objects: 100% (22/22), done.
    remote: Compressing objects: 100% (20/20), done.
    remote: Total 25 (delta 5), reused 3 (delta 0), pack-reused 3
    Receiving objects: 100% (25/25), 34.63 KiB | 2.31 MiB/s, done.
    Resolving deltas: 100% (5/5), done.
    ```
2. Создание ветви `lab_02_a` и `lab_02_b`
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git branch lab_02_a
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git branch lab_02_b
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git branch 
      lab_02_a
      lab_02_b
    * master
    ```
3. Добавление `lab_02_a.txt` и `.gitignore` в ветку `lab_02_a`
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git checkout lab_02_a
    Switched to branch 'lab_02_a'
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> echo "lab_02_a" > lab_02_a.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> echo "*.out" > .gitignore
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> echo "*.exe" >> .gitignore
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> git add *.txt .gitignore
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> git commit -m "lab_02_a"
    [lab_02_a 6e2c0f5] lab_02_a
     2 files changed, 3 insertions(+)
     create mode 100644 .gitignore
     create mode 100644 lab_02_a.txt
    ```
4. Отправка изменения в удалённый репозиторий и создание `merge request` [A](https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/5)
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> git push --set-upstream origin lab_02_a
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 2 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (4/4), 362 bytes | 362.00 KiB/s, done.
    Total 4 (delta 0), reused 0 (delta 0)
    remote:
    remote: To create a merge request for lab_02_a, visit:
    remote:   https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/new?merge_request%5Bsource_branch%5D=lab_02_a
    remote:
    To git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
     * [new branch]      lab_02_a -> lab_02_a
    Branch 'lab_02_a' set up to track remote branch 'lab_02_a' from 'origin'.
    ```
5. Добавление `lab_02_b.txt` и `.gitignore` в ветку `lab_02_b`
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_a)> git checkout lab_02_b
    Switched to branch 'lab_02_b'
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_b)> echo "lab_02_b" > lab_02_b.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_b)> echo "*.o" > .gitignore
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_b)> git add *.txt .gitignore
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_b)> git commit -m "lab_02_b"
    [lab_02_b 3ee397a] lab_02_b
     2 files changed, 2 insertions(+)
     create mode 100644 .gitignore
     create mode 100644 lab_02_b.txt
    ```
6. Отправка изменения в удалённый репозиторий и создание `merge request` [B](https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/6)
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_b)> git push --set-upstream origin lab_02_b
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 2 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (4/4), 352 bytes | 352.00 KiB/s, done.
    Total 4 (delta 0), reused 0 (delta 0)
    remote:
    remote: To create a merge request for lab_02_b, visit:
    remote:   https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/new?merge_request%5Bsource_branch%5D=lab_02_b
    remote:
    To git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
     * [new branch]      lab_02_b -> lab_02_b
    Branch 'lab_02_b' set up to track remote branch 'lab_02_b' from 'origin'.
    ```
### Задание 3.3
1. Клонирование репозитория
    ```bash
    kuznetsovev@kuznetsovev ~/o/lab_02> git clone gitlab@git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
    Cloning into 'iu7-software-engineering-labs-2022-kuznetsovegor'...
    remote: Enumerating objects: 33, done.
    remote: Counting objects: 100% (30/30), done.
    remote: Compressing objects: 100% (19/19), done.
    remote: Total 33 (delta 6), reused 29 (delta 5), pack-reused 3
    Receiving objects: 100% (33/33), 35.19 KiB | 7.04 MiB/s, done.
    Resolving deltas: 100% (6/6), done.
    ```
2. Создание ветки `lab_02_c` и фиксирование файла `test.txt` и отправка в удалённый репозиторий
    ```bash    
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git branch lab_02_c
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git checkout lab_02_c
    Switched to branch 'lab_02_c'
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> vim text.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> jobs
    Job	Group	CPU	State	Command
    1	53604	0%	stoppedvim text.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> fg 1
    fg: No suitable job: 1
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c) [2]> fg 53604
    Send job 1, “vim text.txt” to foreground
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git add text.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git commit -m "lab_02_c 1"
    [lab_02_c 5ecea80] lab_02_c 1
     1 file changed, 9 insertions(+)
     create mode 100644 text.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git push --set-upstream origin lab_02_c
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 2 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 432 bytes | 144.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    remote:
    remote: To create a merge request for lab_02_c, visit:
    remote:   https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/new?merge_request%5Bsource_branch%5D=lab_02_c
    remote:
    To git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
     * [new branch]      lab_02_c -> lab_02_c
    Branch 'lab_02_c' set up to track remote branch 'lab_02_c' from 'origin'.
    ```
3. Изменение файла `test.txt` и фиксирование его
4. Копирование репозитория в другую папку и переключение ветки на `lab_02_c`
    ```bash
    kuznetsovev@kuznetsovev ~/o/lab_02_2> git clone gitlab@git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-eng
    ineering-labs-2022-kuznetsovegor.git
    Cloning into 'iu7-software-engineering-labs-2022-kuznetsovegor'...
    remote: Enumerating objects: 36, done.
    remote: Counting objects: 100% (33/33), done.
    remote: Compressing objects: 100% (22/22), done.
    remote: Total 36 (delta 7), reused 28 (delta 5), pack-reused 3
    Receiving objects: 100% (36/36), 35.50 KiB | 17.75 MiB/s, done.
    Resolving deltas: 100% (7/7), done.
    kuznetsovev@kuznetsovev ~/o/lab_02_2> cd iu7-software-engineering-labs-2022-kuznetsovegor/
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (master)> git checkout lab_02_c
    Branch 'lab_02_c' set up to track remote branch 'lab_02_c' from 'origin'.
    Switched to a new branch 'lab_02_c'
    ```
5. Изменения файла `test.txt`, фиксирование его и отправка в удалённый репозиторий
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git commit -am "lab_02_c 3"
    [lab_02_c 908ba58] lab_02_c 3
     1 file changed, 13 insertions(+)
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> 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), 629 bytes | 629.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    remote:
    remote: To create a merge request for lab_02_c, visit:
    remote:   https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/new?merge_request%5Bsource_branch%5D=lab_02_c
    remote:
    To git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
       5ecea80..908ba58  lab_02_c -> lab_02_c
    ```
6. Попытка отправить изменения в удалённый репозиторий из первой папки
    ```bash
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git push
    To git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
     ! [rejected]        lab_02_c -> lab_02_c (fetch first)
    error: failed to push some refs to 'gitlab@git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    ```
    Это не удаётся сделать по причине появления комита, который не зафиксирован в данном репозитории
7. Разрешение конфликта
    ```bash 
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c) [1]> git pull
    remote: Enumerating objects: 5, done.
    remote: Counting objects: 100% (5/5), done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), 609 bytes | 121.00 KiB/s, done.
    From git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor
       5ecea80..908ba58  lab_02_c   -> origin/lab_02_c
    Auto-merging text.txt
    CONFLICT (content): Merge conflict in text.txt
    Automatic merge failed; fix conflicts and then commit the result.
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c|MERGING) [1]> vim text.txt
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c|MERGING)> git commit -am "merge"
    [lab_02_c 5680633] merge
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git push
    Enumerating objects: 10, done.
    Counting objects: 100% (10/10), done.
    Delta compression using up to 2 threads
    Compressing objects: 100% (6/6), done.
    Writing objects: 100% (6/6), 759 bytes | 759.00 KiB/s, done.
    Total 6 (delta 2), reused 0 (delta 0)
    remote:
    remote: To create a merge request for lab_02_c, visit:
    remote:   https://git.iu7.bmstu.ru/iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor/-/merge_requests/new?merge_request%5Bsource_branch%5D=lab_02_c
    remote:
    To git.iu7.bmstu.ru:iu7-software-engineering/iu7-software-engineering-labs-2022/iu7-software-engineering-labs-2022-kuznetsovegor.git
       908ba58..5680633  lab_02_c -> lab_02_c
    ```
    Для разрешения конфликта требовалось слить эти два состояния и сделать коммит слияния. Только после этого можно было отправить в удалённый репозиторий
    ```bash 
    kuznetsovev@kuznetsovev ~/o/l/iu7-software-engineering-labs-2022-kuznetsovegor (lab_02_c)> git log --graph --branches --oneline
    *   5680633 (HEAD -> lab_02_c, origin/lab_02_c) merge
    |\
    | * 908ba58 lab_02_c 3
    * | 94c1d09 lab_02_c 2
    |/
    * 5ecea80 lab_02_c 1
    * e53debb (origin/master, origin/HEAD, master) initial commit
    ```