1

I am on master branch with 7 commits (say) and moved to commit No. 4 using 'git checkout <commit_hash>' with HEAD being in detached state now.

I made 3 new commits from commit No. 4 with detached HEAD and created a new branch 'dev' there.
Then I checked out to dev and again made a new commit.

Now can I say that all the commits from this dev branch tip commit till root commit of the project belong to dev branch or only the dev tip commit and previous commit belong to dev branch?

What is the concept of belongingness of commits to a branch ?

R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
jaspu
  • 31
  • 1
  • 6

1 Answers1

0

The "belongingness" is: any commit reachable from dev HEAD.

So all commits from dev and the one from master from which dev was created.
See my previous answer "How to list branches that contain a given commit?", using git branch --contains:

With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit)

m--m--m--m1--m--m
         \
          d1--d--d--d
  • git branch --contain m1 would display both dev and master
  • git branch --contain d1 would display only dev
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250