divergent
divergent

Reputation: 291

Git showing previous branch commits in new branch

I'm working on a project that has a bunch of tickets. I'm trying to create a single branch for each ticket containing (ideally) a single commit of the code added/edited as per the specifications of my ticket.

What happens is that I check out a new branch, write my code, commit it and push to remote repo - as normal. However when I push commits from subsequent branches it shows all commits - even from previous branches - with the latest commit simply appended to these in the remote branch.

Why this is happening is beyond me. I expect each new branch to contain only the commits made in that branch. Any help explaining will be greatly appreciated.

Upvotes: 4

Views: 726

Answers (1)

ElpieKay
ElpieKay

Reputation: 30858

You may have some misunderstanding about what a branch is. A branch is a commit with all of its ancestor commits unless the branch has just the root commit which has no ancestors.

Suppose we have a commit history like this:

root-A-B-C-D->master

If you create a new branch dev from master, it's like

root-A-B-C-D->dev

After you make a new commit, the branch dev is now like

root-A-B-C-D-E->dev

E itself cannot make a branch.

How many branches with different commit histories can we make from master? 5 branches. They are

root->sub1
root-A->sub2
root-A-B->sub3
root-A-B-C->sub4
root-A-B-C-D->sub5

Upvotes: 1

Related Questions