简体   繁体   English

我怎么知道我的本地分支是从哪个git远程分支签出的?

[英]How can I know from which git remote branch my local branch was checked out?

I used this command to check out a local branch 'mylocal' from remote branch 'origin/mater'. 我使用此命令从远程分支“ origin / mater”中签出了本地分支“ mylocal”。

git checkout -b mylocal origin/master

But, after awhile I forgot from which remote branch I created my local branch 'mylocal'. 但是,不久之后,我忘记了从哪个远程分支创建了本地分支“ mylocal”。

Is there any git command that I can use to show the corresponding remote branch for my local branch? 我可以使用任何git命令显示本地分支的相应远程分支吗?

Thanks. 谢谢。

If you have upstream information set up for your branch (which git may or may not have done automatically, depending on configuration) then you can use 如果您为分支机构设置了上游信息(取决于配置,git可能会自动完成或可能不会自动完成),则可以使用

git rev-parse --symbolic-full-name --abbrev-ref mylocal@{u}

This should output the remote branch that it was created from. 这应该输出创建它的远程分支。 If such information does not exist, then you're just going to have to compare your branch with the remote branches to see which diverges the most. 如果不存在此类信息,则只需要比较您的分支机构与远程分支机构,以查看差异最大的分支机构。 git show-branch -a might give you the information you want. git show-branch -a可能会为您提供所需的信息。 Alternatively you can do something like git rev-list origin/master..mylocal | wc -l 或者,您可以执行git rev-list origin/master..mylocal | wc -l git rev-list origin/master..mylocal | wc -l to get a count of how many commits away from origin/master you are, and do this with all the remote branches until you find the smallest distance. git rev-list origin/master..mylocal | wc -l可以计算出您距离origin/master有多少个提交,然后对所有远程分支执行此操作,直到找到最小的距离为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM