2

I have a dev-branch, and I want to see the difference between "branch creation" and now. Actually, I'm more interested in the commit that followed the creation of the branch, which is more like "branch creation"+1.

I know I can use shorthand like HEAD and HEAD~1 in Git commands. I don't know how to specify "branch creation".

What is the Git shorthand for "branch creation" and "branch creation"+1?

jww
  • 97,681
  • 90
  • 411
  • 885
  • 3
    Git does not record branch creation, in general. In some specific cases you may be able to find the commit ID in a reflog. Remember, as far as Git is concerned, branches are essentially irrelevant: only *commits* really matter. If you want a system that records branches forever, you don't want Git. If you are OK with "only commits matter", record specific commits using tags. – torek Aug 31 '16 at 03:34
  • @torek I guess he means the closest point of intersection with some other branch. (if so, [see here](http://stackoverflow.com/questions/1549146/find-common-ancestor-of-two-branches)) – M.M Aug 31 '16 at 05:16
  • git log master..branch --oneline | tail -1 , Read this http://stackoverflow.com/a/32870852/1270865 – cafebabe1991 Aug 31 '16 at 10:00

3 Answers3

2

There's a fundamental problem with your question: what exactly is "branch creation"? A "branch" is just a pointer to a commit, which itself has a reference to a parent commit, which has a reference to a parent commit, and so forth backwards through time.

If I draw my git history like this:

a -> b -> c -> d (master)
      \
       -> x -> y (devbranch)

Then you might say the answer is obvious. But the fact is that the history could also be drawn like this:

a -> b -> x -> y (devbranch)
     \
      -> c -> d

That's the same thing. There is no specific "creation" of a branch; it's just a label applied to the tip of a chain of commits.

You might be able to get the answer you're looking for with the merge-base command, something like:

git checkout devbranch
git merge-base master HEAD

That will find "the best common ancestor(s) between two commits to use in a three-way merge," which in simple cases is probably going to be the point at which two branches diverge.

larsks
  • 277,717
  • 41
  • 399
  • 399
1

You cannot see how a branch was created. This information is not saved. The branch points to a commit right now, and that's pretty much it. It is a very light weight object and very easy to set to point to some other commit, losing the history of the branch since creation.

Martin G
  • 17,357
  • 9
  • 82
  • 98
  • I should have known there was no `TAIL` or similar given how poorly Git does with logging and branch support. I tried to get the question deleted but it was too late (there were already answers). I'm continually amazed at Git's penchant to take a simple task and make it difficult to impossible. – jww Aug 31 '16 at 10:45
0

you can use command as the following.

git diff topic...master

It means Changes that occurred on the master branch since when the topic branch was started off it

Quoted help of git diff

   git diff [--options] <commit>...<commit> [--] [<path>...]
       This form is to view the changes on the branch containing and up to
       the second <commit>, starting at a common ancestor of both <commit>. 
       "git diff A...B" is equivalent to 
       "git diff $(git-merge-base A B) B". You can omit any one of 
        <commit>, which has the same effect as using HEAD instead.

Also, you can see Find the parent branch of a git branch for how to find parent branch.

Community
  • 1
  • 1
gzh
  • 3,507
  • 2
  • 19
  • 23
  • 1
    This works from the *merge base*, which, after a merge occurs, has nothing to do with the original branch creation. That *may* be what is desired after all (it's much more generally useful, for instance) but it's not what was asked-for. Other (non-Git) VCSes can and do provide what was asked-for, though at a price. – torek Aug 31 '16 at 05:33