Git Tutoriaal


Git en {{title}}


Git Dra by


Git Gevorderd


Git Undo




Git Branch Merge


Voeg takke saam

Ons het die noodoplossing gereed, en so laat ons die meester- en noodherstel-takke saamsmelt.

Eerstens moet ons na die meestertak verander:

Voorbeeld

git checkout master
Switched to branch 'master'

Nou voeg ons die huidige tak (meester) saam met noodoplossing:

Voorbeeld

git merge emergency-fix
Updating 09f4acd..dfa79db
Fast-forward
 index.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Aangesien die noodhersteltak direk van meester af gekom het, en geen ander veranderinge aan meester gemaak is terwyl ons gewerk het nie, sien Git dit as 'n voortsetting van meester. Dit kan dus "Snel vorentoe", net wys beide meester en nood-fix na dieselfde commit.

Aangesien meester en noodoplossing nou in wese dieselfde is, kan ons noodoplossing uitvee, aangesien dit nie meer nodig is nie:

Voorbeeld

git branch -d emergency-fix
Deleted branch emergency-fix (was dfa79db).

Voeg konflik saam

Nou kan ons oorbeweeg na hallo-wêreld-beelde en aanhou werk. Voeg nog 'n prentlêer (img_hello_git.jpg) by en verander index.html, sodat dit dit wys:

Voorbeeld

git checkout hello-world-images
Switched to branch 'hello-world-images'

Voorbeeld

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>

<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<p>A new line in our file!</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>

</body>
</html>

Nou, ons is klaar met ons werk hier en kan opvoer en commit vir hierdie tak:

Voorbeeld

git add --all
git commit -m "added new image"
[hello-world-images 1f1584e] added new image
 2 files changed, 1 insertion(+)
 create mode 100644 img_hello_git.jpg

Ons sien dat index.html in beide takke verander is. Nou is ons gereed om hallo-wêreld-beelde saam te voeg tot meester. Maar wat sal gebeur met die veranderinge wat ons onlangs in meester gemaak het?

Voorbeeld

git checkout master
git merge hello-world-images
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Die samesmelting het misluk, aangesien daar konflik tussen die weergawes vir index.html is. Kom ons kyk na die status:

Voorbeeld

git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
        new file:   img_hello_git.jpg
        new file:   img_hello_world.jpg

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

Dit bevestig dat daar 'n konflik in index.html is, maar die prentlêers is gereed en opgestel om gepleeg te word.

So ons moet daardie konflik regstel. Maak die lêer oop in ons redigeerder:

Voorbeeld

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>

<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<<<<<<< HEAD
<p>This line is here to show how merging works.</p>
=======
<p>A new line in our file!</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>
>>>>>>> hello-world-images

</body>
</html>

Ons kan die verskille tussen die weergawes sien en dit wysig soos ons wil:

Voorbeeld

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>

<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<p>This line is here to show how merging works.</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>

</body>
</html>

Nou kan ons index.html verhoog en die status nagaan:

Voorbeeld

git add index.html
git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:
        new file:   img_hello_git.jpg
        new file:   img_hello_world.jpg
        modified:   index.html

Die konflik is reggestel, en ons kan commit gebruik om die samesmelting af te handel:

Voorbeeld

git commit -m "merged with hello-world-images after fixing conflicts"
[master e0b6038] merged with hello-world-images after fixing conflicts

En vee die hallo-wêreld-beelde-tak uit:

Voorbeeld

git branch -d hello-world-images
Deleted branch hello-world-images (was 1f1584e).

Nou het jy 'n beter begrip van hoe takke en samesmelting werk. Tyd om met 'n afgeleë bewaarplek te begin werk!

Toets jouself met oefeninge

Oefening:

Voeg die hello-youtak saam met die huidige tak:

git  hello-you