Git - rebase zamiast merge

Autor podstrony: Krzysztof Zajączkowski

Stronę tą wyświetlono już: 309 razy

Czas spróbować rebase zamiast merge. W tym celu upewniwszy się, że jestem na develop-ie stworzę branch-a o nazwie 003_styles:

git checkout -b 003_styles

Następnie dodam trochę styli do strony w pliku style.css:

html, body { padding: 0; } h2 { text-align: center; } aside { width: 200px; max-width: 100vw; margin: 5px; padding: 5px; border-radius: 5px; margin: auto; background-color: azure; text-align: center; } aside:hover { background-color: beige; }

I jeszcze zmiana wpliku index.html:

<!DOCTYPE html> <html lang="PL"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"></link> <title>Zabawa z gitem!</title> </head> <body> <h2>Zabawa z gitem</h2> <aside> Git zabawny wszakże jest Kontroluje wszystko wnet! </aside> </body> </html>

Czas dodać zmiany:

git add *
PS C:UsersJaDesktopgit_playground> git commit -m "add styles"
[003_styles 3eea9e5] add styles
 2 files changed, 23 insertions(+)
 create mode 100644 style.css

A teraz przełączę się na 002_some_content:

git checkout 002_some_content

i zmienię w index.html tekst:

<aside> Git zabawny wszakże jest Kontroluje wszystko wnet! </aside>

na:

<aside> Git zabawny wszakże jest Kontroluje wszystko wnet! Cuda zdziała i mergeuje Rebasuje konflikuje </aside>

I dodaję zmiany:

git add *
git commit -m "more poem"
[002_some_content 8037ef7] more poem
 1 file changed, 2 insertions(+)

Teraz merge-uję:

git merge develop 
Auto-merging index.html
Merge made by the 'recursive' strategy.
 index.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Gdyby były konflikty w tym przypadku rozwiązałbym je na moim 002_some_content a następnie rozwiązałbym je lokalnie. Teraz muszę przełączyć się na develop-a:

git checkout develop

I merge 002_some_content:

git merge 002_some_content
Updating e1928fc..d3b1c61
Fast-forward
 index.html | 2 ++
 1 file changed, 2 insertions(+)

teraz przełączam się na 003_styles:

git checkout 003_styles

I w końcu rebase:

git rebase develop
First, rewinding head to replay your work on top of it...
Applying: add styles

Teraz ten branch może zostać merge-owany w trybie straight forward:

git checkout develop
git merge 003_styles
Updating d3b1c61..3e20fe3
Fast-forward
 index.html |  1 +
 style.css  | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 style.css

Małe diagramy gdy działania rebase gdy nie ma konfliktów:

          A---B---C topic
         /
    D---E---F---G master
po
                  A'--B'--C' topic
                 /
    D---E---F---G master

Zaś gdy zawiera konflikty:

          A---B---C topic
         /
    D---E---A'---F master
po
                   B'---C' topic
                  /
    D---E---A'---F master