Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - how to find first commit of specific branch

Tags:

git

In following example tree:

A-B-C-D-E (master branch)     \      F-G-H (xxx branch) 

I'm looking for F - the first commit in xxx branch. I think that it is possible with:

git log xxx --not master 

and the last listed commit should be F. Is it correct solution or maybe there are some disadvantages of it?

I know that there were similar questions on stackoverflow, but nobody proposed such solution, and I'm not sure if I do it right.

like image 496
user2699113 Avatar asked Aug 23 '13 16:08

user2699113


People also ask

How can I see commits from one branch?

Git rev-list will list commits in one branch that are not in another branch. It is a great tool when you're trying to figure out if code has been merged into a branch or not. Using the --oneline option will display the title of each commit.

How can I see my first commit?

You can just reverse your log and just head it for the first result. git log --reverse reverses the history, so you have to use head -1 instead of tail -1 to get the first commit.

How do I find a specific commit in git?

If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .

What is a first git commit?

The first commit that a developer makes when they start a new software project is called the initial commit.


2 Answers

git log master..branch --oneline | tail -1 

Where "branch" is your specific branch name. The dot-dot gives you all of the commits that the branch has that master doesn't have. tail -1 returns the last line from the previous output.

like image 64
konyak Avatar answered Sep 28 '22 09:09

konyak


You should use the merge-base functionality which is designed to solve exactly this:

git merge-base remotes/origin/<branch> develop  
like image 35
Fabrizio Stellato Avatar answered Sep 28 '22 08:09

Fabrizio Stellato