Pretend I branched from my master branch to a topic branch, and then I did a few commits on my topic branch. Is there a command that tells me the commit hash on the master branch that my topic branch originated from?
Ideally, I wouldn't have to know how many commits I've made ( trying to avoid HEAD^5 ).
I've googled and SO'd around and can't seem to land on the answer. Thanks!
Take a look at config file, perhaps there is branch. <branchname>. merge entry, which would tell you what branch this one is based on. You can also try git show-branch <branch> master , as an alternative.
In Git, get the tree hash with: git cat-file commit HEAD | head -n1. The commit hash by hashing the data you see with cat-file . This includes the tree object hash and commit information like author, time, commit message, and the parent commit hash if it's not the first commit.
The commit hash is an SHA-1 hash made up of a few properties from the commit itself. As mentioned above, it is a lot more complex than this post can go into, but understanding the fundamentals is a great first step. The git hash is made up of the following: The commit message. The file changes.
You can use git reflog show --no-abbrev <branch name>
. It will output all changes made to the branch, including it's creation, for example (I created branch xxx
from master
branch):
bdbf21b087de5aa2e78a7d793e035d8bd9ec9629 xxx@{0}: branch: Created from master
Note that this is not very reliable as reflog records can expire (90 days by default), and it seems like there is no 100% reliable way to do this.
use git merge-base master your-branch
to find the best common ancestor between two branches (usually the branching point).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With