Tuesday, February 8, 2022

Git Rebase and Git Merge

 

Merge

 Step1:- Initialize a new git repo

              git init

 Step2:- Create 3 files m1 m2 m3 in master branch

             touch m1 m2 m3

             git add -A

            git commit -m "m1" m1

            git commit -m "m2" m2

            git commit -m "m3" m3

Step3:- Create a branch feature1

            git branch feature1

            git checkout feature1

            touch f1

            git add f1

            git commit -m "f1"

Step 4:- Check the feature1 git log details

            git log --oneline

            c399395 (HEAD -> feature1) f1

            267cedc (master) m3

            ead6829 m2

            0ad4148 m1


Step5:- Goto master branch and commit  a new m4 file.

            git checkout master

             touch m4

             git add .

             git commit -m "m4"

Step6:- Got feature1 branch and merge master branch

              git checkout feature1

              git merge master

               git log --oneline

c2a0841 (HEAD -> feature1) Merge branch 'master' into feature1

 m4

 f1

 m3

 m2

 m1


Rebase

Step1:- Initialize a new git repo

              git init

 Step2:- Create 3 files m1 m2 m3 in master branch

             touch m1 m2 m3

             git add -A

            git commit -m "m1" m1

            git commit -m "m2" m2

            git commit -m "m3" m3

Step3:- Create a branch feature1

            git branch feature1

            git checkout feature1

            touch f1

            git add f1

            git commit -m "f1"

Step 4:- Check the feature1 git log details

            git log --oneline

            c399395 (HEAD -> feature1) f1

            267cedc (master) m3

            ead6829 m2

            0ad4148 m1


Step5:- Goto master branch and commit  a new m4 file.

            git checkout master

             touch m4

             git add .

             git commit -m "m4"

Step6:- Got feature1 branch and merge master branch

              git checkout feature1

              git rebase master

               git log --oneline

c2a0841 (HEAD -> feature1) Merge branch 'master' into feature1

 f1

 m4

 m3

 m2

 m1



0 comments:

Post a Comment