I am following this answer to understand the difference between git merge
and rebase
and also created a sample repository in Github to understand it well, but what I am watching is the same number of commits with both git merge and rebase operation.
Let me explain what I performed.
Step 1: I created a project and pushed it to master branch of Github repository.
Step 2: Created feature branch with name - feature-one with base as master branch, added dummy files and committed it as follows:
git checkout -b feature-one
touch test.txt
git add .
git commit -m "feature-one first commit"
touch another-test.txt
git add .
git commit -m "feature-one second commit"
Step 3: Switched back to master branch and merged the feature-one branch in it using git merge
as follows:
git checkout master
git merge feature-one
Now I can see two additional commits(feature-one first commit, feature-one second commit) in master along with initial commit.
Then, I done the same steps and rebased it with git master branch as follows:
git checkout -b feature-one
touch test-rebase.txt
git add .
git commit -m "feature-one third commit"
touch another-test-rebase.txt
git add .
git commit -m "feature-one fourth commit"
Step 4: Switched back to master branch and merged the feature-one branch in it using git rebase
as follows:
git checkout master
git rebase feature-one
Now again I can see two additional commits(feature-one third commit, feature-one fourth commit) in master along with previous three commits.
What's my expectation is I will not see the feature branch commits once rebased with master.
Now my question is my expectation correct or am doing something wrong?
Can anyone please explain?
Thanks.