0

I have a branch lets say dev. I created my feature branch from dev. dev has commits starting from 2014.

So

  dev 
    |
    ---FeatureBranch created on June 10 2021

I made my 10 commits on my feature branch lets say on June 10, June 11, June 12.

How can I get first commit on my feature branch?

I tried git log --reverse but would give me first commit as 2014 because my feature branch will consist all commits from dev branch too.

How can I get the first commit id on my feature branch after it was created from dev?

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
arpit joshi
  • 1,987
  • 8
  • 36
  • 62
  • 1
    Does this answer your question? [Git - how to find first commit of specific branch](https://stackoverflow.com/questions/18407526/git-how-to-find-first-commit-of-specific-branch) – SwissCodeMen Jun 11 '21 at 21:15
  • 1
    The first commit of the feature branch *is* the first commit of the dev branch. (If you're used to other version control systems, this aspect of Git seems really weird ... but it's true!) What you want is the first commit of the feature branch that's not *also on* the dev branch. (Also, your title says `master` but your text body says `dev`.) – torek Jun 12 '21 at 02:43
  • name of my master branch is dev . – arpit joshi Jun 12 '21 at 03:35

1 Answers1

1

You might be looking for

git log --oneline dev..feature --reverse

That's the commits on feature but not on dev, in reverse order, so the first one is the one you're looking for. There are much cooler ways to do this, but that's the simple and obvious way.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 2
    And various variations on that where you can pile to `| head -n 1` to ensure you just get the first one. Or omit the `--reverse` and pipe to `|tail -n 1` – Mort Jun 11 '21 at 21:16
  • I tried it but still gives me commits from dev branch .Also to note the feature branch might also get updated regularly ie:taking updates from dev branch regularly – arpit joshi Jun 11 '21 at 23:13
  • Well it works fine if your topology is right. You've given no information about that. – matt Jun 12 '21 at 00:01