Git how to see the first commit of a branch made from master.
Branches are not made from branches.
There's a bit of a problem with this claim, which is: we haven't really defined the term branch. The word "branch" in Git does not have just one meaning. It has at least two or three. See also What exactly do we mean by "branch"? But whichever meaning we use, branches are not related to other branches the way you would like.
For example I master branch then commited C1,C2,C3 now created another branch from C3 called myFirstBranch ,
(Note that you just said C3
was the last commit on master
when you created myFirstBranch
.)
SO now Master commit C1,C2,C3,C4,C5..... myFirstBranch --------------(Made from C3)D1,D2,D3.....
Let's draw this, with newer commits towards the right (although Git normally puts newer commits towards the top in git log
output):
C4--C5 <-- master
/
C1--C2--C3
\
D1--D2--D3 <-- myFirstBranch
The name master
, in this drawing, means commit C5
. The name myFirstBranch
means commit D3
. However, we often care not just about the last commit, as identified by the branch name, but also all earlier commits as well.
The drawing shows pretty clearly that commits C1
through C3
are "on" (or reachable from, if we want to be more precise) both branches. That's why the command you are using is telling you that C1
is the first commit that is "on" (reachable from) myFirstBranch
: because it really is!
The name master
can mean either commit C5
only, or commit C5
and all earlier commits (thus reaching back to C1
). The name myFirstBranch
can, similarly, mean D3
only, or D3
and all earlier commits. Git therefore gives us a way to do set difference. Rather than the more typical math notation of myFirstBranch \ master
or myFirstBranch - master
, though, it's expressed as master..myFirstBranch
or myFirstBranch ^master
.
(Both of these do the same thing in git log
and other Git commands.)
The drawback here is that this requires you to know which set to subtract away from your own set. Branches—branch names, in Git—do not remember their "parent branch name" either, even though that would provide an automatic way to do this subtraction.
(It's possible to use Git's reflog entries to figure this stuff out semi-automatically, but there is a drawback to trying to do things this way: the reflog entries expire, typically after 90 days, after which it becomes impossible to compute.)
Edit: in a comment, you say:
in the above diagram I made the myFirstBranch branch from C5
This contradicts your earlier claim that you used C3
; but let's draw that:
C1--C2--C3--C4--C5 <-- master
\
D1--D2--D3 <-- myFirstBranch
Again, the commit selected by the name myFirstBranch
is D3
. As before, D3
has D2
as its parent, and D2
has D1
as its parent. But this time, D1
has C5
as its parent. So this means that all eight commits are on (or contained in) myFirstBranch
while only five commits are on / contained-in master
.
Still, git log master..myFirstBranch
will select commits D1
-through-D3
(in the other order, since Git starts at the end—at the commit to which the name points—and works backwards).