git git如何找到分支起源的提交哈希
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3998883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git how to find commit hash where branch originated from
提问by brycemcd
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 ).
理想情况下,我不必知道我做了多少提交(试图避免 HEAD^5 )。
I've googled and SO'd around and can't seem to land on the answer. Thanks!
我已经用谷歌搜索并搜索过了,似乎无法找到答案。谢谢!
采纳答案by knittl
use git merge-base master your-branch
to find the best common ancestor between two branches (usually the branching point).
用于git merge-base master your-branch
查找两个分支之间的最佳公共祖先(通常是分支点)。
回答by max
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):
您可以使用git reflog show --no-abbrev <branch name>
. 它将输出对分支所做的所有更改,包括它的创建,例如(我xxx
从master
分支创建了分支):
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.
请注意,这不是很可靠,因为 reflog 记录可能会过期(默认为 90 天),而且似乎没有 100% 可靠的方法可以做到这一点。
回答by Rick Wildes
The only 100% reliable way to do this is to tag the beginning of your branch when you create it. The accepted answer will not work if you merge commits back to the branch you originated your new branch from. This is sometimes done for example if you are creating a stabilizing release branch and want to merge back your fixes you find during release testing back to master. A common thing to do. If you know you will never merge commits from your new branch back to the originating branch then the accepted answer will work.
唯一 100% 可靠的方法是在创建分支时标记分支的开头。如果您将提交合并回您创建新分支的分支,则接受的答案将不起作用。例如,如果您正在创建一个稳定的发布分支并希望将您在发布测试期间找到的修复程序合并回主版本,则有时会这样做。很常见的事情。如果您知道永远不会将来自新分支的提交合并回原始分支,那么接受的答案将起作用。