1

Branch from master branch

git checkout -b feature-abc
# update several times on this feature branch.
git add ...; git commit ...  ; git push ...

Now I'd like to know how to get its parent branch name (should be master branch) and which latest commit I checked out before.

Maybe I merged from master branch several times, I need know the latest commit hash id from its parent branch.

master branch

1 -> 2 -> 3 -> 4 -> 5-> 
     |         |
     |-> 1 -> ---> 2

feature-abc

So currently I am at feature branch (2), how I get the commit hash of 4?

What commands I can run to get these information?

1
  • Branch names do not have parent branch names. They are, in effect, just sticky-note labels attached to commits. The act of making a new commit causes whichever branch is the current branch to have its label peeled off the old commit and put on the new one. Many labels can be stuck on a single commit; only one moves (automatically) by the act of committing; and no label has any parent/child relationship with any other label. Commented Feb 15, 2019 at 6:45

1 Answer 1

3
git rev-list master..feature --boundary

will show

  • all commit hashes which are on your feature branch but not on master
  • the last common commit ("4" in your example) prefixed by a "-"

So if you ignore all lines without a "-", you will find your commit 4.

Since git log is based on git rev-list, you can also use this together with git log, for example:

git log master..feature --boundary --oneline

is quite informative.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.