Learning objectives:
git merge and git rebase.At the end of this lab, you will be able to:
git merge and git rebase to integrate branch changes.merge and rebase.Create a working folder for this lab:
mkdir git-evaluation-1
cd git-evaluation-1
git initScreenshot: Take a screenshot showing the repository initialization (git init).
Create the initial file
Create a file named fichier1.txt (original file) and add a base commit on the main branch main:
echo "Contenu initial dans fichier1" > fichier1.txt
git add fichier1.txt
git commit -m "Initialize the project with fichier1.txt"Rename the main branch to main (if needed):
git branch -M mainScreenshot: Show the file addition and the first commit.
Create the branche1 and branche2 branches from main:
branche1:
git checkout -b branche1main and create branche2:
git checkout main
git checkout -b branche2Create the working branches:
branche-rebase from branche1:
git checkout branche1
git checkout -b branche-rebasebranche-merge from branche2:
git checkout branche2
git checkout -b branche-mergeScreenshot: Show the branch creation with the git branch command.
branche-rebase and branche-mergeNote: We will use different files (
fichier-2-rebase.txtandfichier-2-merge.txt) and perform the same modifications so we can compare the effects ofmergeandrebase.
Work on branche-rebase:
First commit:
git checkout branche-rebase
echo "Modification 1 dans branche-rebase" > fichier-2-rebase.txt
git add fichier-2-rebase.txt
git commit -m "Add fichier-2-rebase.txt with modification 1"Second commit:
echo "Modification 2 dans branche-rebase" >> fichier-2-rebase.txt
git add fichier-2-rebase.txt
git commit -m "Add modification 2 in fichier-2-rebase.txt"Third commit:
echo "Modification 3 dans branche-rebase" >> fichier-2-rebase.txt
git add fichier-2-rebase.txt
git commit -m "Add modification 3 in fichier-2-rebase.txt"Work on branche-merge:
First commit:
git checkout branche-merge
echo "Modification 1 dans branche-merge" > fichier-2-merge.txt
git add fichier-2-merge.txt
git commit -m "Add fichier-2-merge.txt with modification 1"Second commit:
echo "Modification 2 dans branche-merge" >> fichier-2-merge.txt
git add fichier-2-merge.txt
git commit -m "Add modification 2 in fichier-2-merge.txt"Third commit:
echo "Modification 3 dans branche-merge" >> fichier-2-merge.txt
git add fichier-2-merge.txt
git commit -m "Add modification 3 in fichier-2-merge.txt"Screenshot: Show the commits made in each branch with git log.
merge and rebaseRebase of branche-rebase into branche1:
Switch to branche1:
git checkout branche1Rebase branche-rebase into branche1:
git rebase branche-rebaseScreenshot: Use git log --oneline --graph --all to show the linear history created by the rebase.
Merge of branche-merge into branche2:
Switch to branche2:
git checkout branche2Merge branche-merge into branche2:
git merge branche-merge -m "Merge branche-merge into branche2"Screenshot: Use git log --oneline --graph --all to show the history with the merge commit.
Compare the histories:
branche1 (with rebase) and that of branche2 (with merge)?Arguments for each method:
rebase to integrate changes?merge more advantageous?Application scenarios:
merge could cause conflicts in the history, and how rebase could solve this problem.rebase could make tracking difficult in a collaborative project.To submit this lab: