114 lines
3.5 KiB
Markdown
114 lines
3.5 KiB
Markdown
# Git rebase
|
|
|
|
Иллюстрация работы режима слияния rebase
|
|
|
|
git checkout main && git pull
|
|
|
|
## Создайте новую ветку
|
|
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git checkout -b feature1
|
|
Switched to a new branch 'feature1'
|
|
datamove@magisterslinux:~/practice-repo2$ git branch -v
|
|
* feature1 faf40d3 changed to git4
|
|
main faf40d3 changed to git4
|
|
```
|
|
|
|
git status
|
|
|
|
что-то в ней сделайте
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ echo 'print("new feature1")' > feature1.py
|
|
datamove@magisterslinux:~/practice-repo2$ git add feature1.py
|
|
datamove@magisterslinux:~/practice-repo2$ git commit -m "added feature1" feature1.py
|
|
[feature1 3af75f7] added feature1
|
|
1 file changed, 1 insertion(+)
|
|
create mode 100644 feature1.py
|
|
```
|
|
|
|
смотрим лог коммитов
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git log --oneline
|
|
3af75f7 (HEAD -> feature1) added feature1
|
|
faf40d3 (origin/main, origin/HEAD, main) changed to git4
|
|
```
|
|
|
|
## симулируем изменени в главной ветке - обновляем какой-то другой файл
|
|
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git checkout main
|
|
Switched to branch 'main'
|
|
Your branch is up to date with 'origin/main'.
|
|
datamove@magisterslinux:~/practice-repo2$ ls -al
|
|
total 24
|
|
drwxr-xr-x 3 datamove masters 4096 Oct 19 10:44 .
|
|
drwxr-x--- 8 datamove masters 4096 Oct 19 10:43 ..
|
|
drwxr-xr-x 8 datamove masters 4096 Oct 19 10:44 .git
|
|
-rw-r--r-- 1 datamove masters 1799 Oct 19 10:39 .gitignore
|
|
-rw-r--r-- 1 datamove masters 16 Oct 19 10:39 README.md
|
|
-rw-r--r-- 1 datamove masters 21 Oct 19 10:39 hello.py
|
|
datamove@magisterslinux:~/practice-repo2$ vi hello.py
|
|
datamove@magisterslinux:~/practice-repo2$ git commit -m "rebase feature test in main" hello.py
|
|
[main dbc171d] rebase feature test in main
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
```
|
|
|
|
проверяем коммит
|
|
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git log --oneline
|
|
dbc171d (HEAD -> main) rebase feature test in main
|
|
```
|
|
|
|
## выполяем ребейз
|
|
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git checkout feature1
|
|
Switched to branch 'feature1'
|
|
datamove@magisterslinux:~/practice-repo2$ git rebase main
|
|
Successfully rebased and updated refs/heads/feature1.
|
|
datamove@magisterslinux:~/practice-repo2$ git log --oneline
|
|
be92088 (HEAD -> feature1) added feature1
|
|
dbc171d (main) rebase feature test in main
|
|
faf40d3 (origin/main, origin/HEAD) changed to git4
|
|
```
|
|
|
|
## сливаем в главную ветку
|
|
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git checkout main
|
|
Switched to branch 'main'
|
|
Your branch is ahead of 'origin/main' by 1 commit.
|
|
(use "git push" to publish your local commits)
|
|
|
|
datamove@magisterslinux:~/practice-repo2$ git log --oneline
|
|
dbc171d (HEAD -> main) rebase feature test in main
|
|
faf40d3 (origin/main, origin/HEAD) changed to git4
|
|
d29ce9d change to git3 after conflict
|
|
094dc35 change to git3
|
|
2dccff9 changed to git2
|
|
ba55fbd change to git2
|
|
f3643ec hello git programm
|
|
5f1d7af Initial commit
|
|
|
|
datamove@magisterslinux:~/practice-repo2$ git merge feature1
|
|
Updating dbc171d..be92088
|
|
Fast-forward
|
|
feature1.py | 1 +
|
|
1 file changed, 1 insertion(+)
|
|
create mode 100644 feature1.py
|
|
|
|
datamove@magisterslinux:~/practice-repo2$ git log --oneline
|
|
be92088 (HEAD -> main) added feature1
|
|
dbc171d rebase feature test in main
|
|
faf40d3 (origin/main, origin/HEAD) changed to git4
|
|
```
|
|
|
|
## Удаляем ветку разработки
|
|
|
|
```bash
|
|
datamove@magisterslinux:~/practice-repo2$ git branch -d feature1
|
|
Deleted branch feature1 (was be92088).
|
|
```
|
|
|