GIT-如何知道分支的分支机构? [英] GIT - How to know the branch a branch branched from?

查看:79
本文介绍了GIT-如何知道分支的分支机构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

支持我从一个提交创建了多个分支(aaa,bbb,ccc).然后,我从一个分支(bbb)中创建一个新分支(ddd)并对其进行提交.

Support I create multiple branches (aaa, bbb, ccc) from a commit. Then, I create a new branch (ddd) from one of the branch (bbb) and a make a commit on it.

然后,我将所有内容推送到遥控器.另一个人怎么知道新分支(ddd)来自哪个分支?

Then I pushed everything to a remote. How would another person knows the new branch (ddd) comes from which branch?

我执行的git命令是:

The git commands I did was:

git分支aaa
git branch bbb
git branch ccc
git branch ddd bbb
git checkout ddd
echo 2 >>文件
git添加文件
git commit -m"2"

git branch aaa
git branch bbb
git branch ccc
git branch ddd bbb
git checkout ddd
echo 2 >> file
git add file
git commit -m "2"

然后git日志就会显示

And the git log would show


*提交d259a3b(HEAD,ddd)
|
| 2个
|

* commit efb038c(develop,ccc,bbb,aaa)
|
| 1个
|

*提交dd24bb6(管理员)


* commit d259a3b (HEAD, ddd)
|
| 2
|

* commit efb038c (develop, ccc, bbb, aaa)
|
| 1
|

* commit dd24bb6 (master)

甚至有可能知道ddd是从bbb分支出来的吗?

It is even possible to know that ddd was branched from bbb?

谢谢

推荐答案

通常,这确实是不可能的. Git仅 1 记录引用名称(例如分支或标记)指向的单个提交ID(SHA-1).该 commit 的历史记录完全由该提交的父ID(不记录分支名称)确定.当您推送到远程服务器时,您的推送"操作将发送您正在推送的提交的SHA-1(以及其他任何链接对象(树和文件,父提交等)的更多SHA-1,以及所有内容这些对象(根据遥控器上缺少的对象),并要求遥控器将分支设置为指向新的SHA-1.

It is indeed impossible in general. Git records only1 the single commit-ID (SHA-1) to which a reference name (such as a branch or tag) points. The history of that commit is determined solely by that commit's parent IDs, which do not record branch-names. When you push to a remote, your "push" operation sends the SHA-1 of the commit you're pushing (plus more SHA-1s for any other linked objects—trees and files, parent commits, etc—plus the contents of all those objects, as needed based on what's missing on the remote), and asks the remote to set its branch to point to the new SHA-1.

换句话说,您告诉远程服务器:在这里,提交1234567,并设置分支标签ddd = 1234567".它可能会告诉您要执行此操作,我还需要其他五次提交",您已将其中之一标记为bbb,但是如果您不告诉远程服务器,对了,请将标签bbb也设置为该另一次提交" ",那么它到处都不会有该信息.

In other words, you tell the remote: "here, have commit 1234567, and set branch label ddd = 1234567". It may tell you "to do that I need five other commits", one of which you have labeled as bbb, but if you don't tell the remote "oh by the way set label bbb to this other commit too" then it won't have that information anywhere.

1 这有点夸张:git还在reflog中记录存储在标签(包括分支标签)中的每个SHA-1.因此,可以回顾标签的历史以弄清楚标签的开始位置".但是,这有两个限制:reflog纯粹是本地的,从不通过获取或推送进行传输;在这种情况下,更新通常会在90天后过期(尽管这是可以配置的,并且存在其他复杂性).因此,只要我们说有一个推动步骤,或者允许超过3个月的时间,就没有办法告诉您.

1This is a bit of an overstatement: git also records, in the reflog, each SHA-1 that is stored in a label, including branch labels. It is therefore possible to walk back through the label's history to "figure out where it started". There are two limits on this though: reflogs are purely local, never transmitted by fetch or push; and reflogs expire, generally after 90 days in these cases (although this is configurable and there are additional complexities). So as long as we say there's a push step, or allow more than 3 months to pass, there's no way to tell.

这篇关于GIT-如何知道分支的分支机构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆