Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

Locate starting point of git branch

I'd like to be able to locate and ideally log only the commits for my branch (experiment). In other words, from HEAD of experiment to its starting point. It would be nice if I did not need to know the parent branch.

The reason why

git log HEAD..master

doesn't work for me, is because master is ahead of my branch:

A---B---F---G master
     
      C---D---E experiment

For the same reason, this post doesn't answer my question.

EDIT:
The reason why I was having trouble is I changed the history on experiment and it diverged from master so git logged all the commits in the branch, since it never found the point that the they shared history. Accepting answer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you branched from master and are now on experiment, then stay on experiment and say

git log master..

Example on my machine. First, actual situation:

% git log --all --oneline --graph
* 5368511 (HEAD -> experiment) z
* 7f0990f y
* 5c7d1be x
| * d0d5a50 (master) c
| * 47a21c4 b
|/  
* 4dcb110 a

And then we say:

% git log --graph --oneline master..
* 5368511 (HEAD -> experiment) z
* 7f0990f y
* 5c7d1be x

But this does not meet the requirement that you don't want to have to work out what branch you branched from. It is actually quite hard to discover that, because Git has no concept of "branched from". We just did a big discussion of that here:

git: diff between current branch and branch creation

You can see it's exactly the same issue: if you know what branch you "branched from", this is easy. If you don't, not so much.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...