git 如何判断我的分支基于哪个远程“父”分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6456546/
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
How can I tell which remote "parent" branch my branch is based on?
提问by Andrew Falanga
I have a scenario in which there a several remote tracking branches within my local repository that I must sync up to. Our workflow model is:
我有一个场景,其中我必须同步到本地存储库中有几个远程跟踪分支。我们的工作流模型是:
- make a branch locally, based off of the desired remote tracking branch
- make our changes
- build/test/fix
- commit
- push back to the remote server
- 根据所需的远程跟踪分支在本地创建一个分支
- 做出我们的改变
- 构建/测试/修复
- 犯罪
- 推回远程服务器
I've noticed that "git status" doesn't show me what branch my local branch is based on unless something has changed; i.e. uncommitted local changes or a recent fetch puts my local branch behind the times. Is there some way of knowing what branch my local branch is based on without having to change things? Something like, "git status -showparentbranch" or some other command that would show this. Occasionally I run into this need but don't know yet how to satisfy it.
我注意到“git status”不会显示我的本地分支所基于的分支,除非发生了一些变化;即未提交的本地更改或最近的获取使我的本地分支落后于时代。有什么方法可以知道我的本地分支基于哪个分支而无需更改?类似于“git status -showparentbranch”或其他一些可以显示此内容的命令。有时我会遇到这种需求,但还不知道如何满足它。
回答by elrrrrrrr
try this:
尝试这个:
git log --graph --decorate
回答by Adam Dymitruk
Git does not track what branches a commit was put through. There is no way to tell. If the commits happened on your repo, then you can inspect the reflog, but that's about it. Take a look at the explanation of the DAG in the Pro Git book- also read up on reflog in there.
Git 不会跟踪提交通过了哪些分支。没有办法告诉。如果提交发生在您的 repo 上,那么您可以检查 reflog,但仅此而已。看看Pro Git 书中对 DAG 的解释- 也可以阅读那里的 reflog。
You can also visualize history better with gitk --all
or git log --graph --decorate
您还可以使用gitk --all
或更好地可视化历史git log --graph --decorate
Hope this helps.
希望这可以帮助。
回答by david.libremone
git branch -vv
will:
git branch -vv
将要:
- list allyour local branches
- display the name of the remote branch next to each local branch
- highlight the active local branch
- 列出您当地的所有分支机构
- 在每个本地分支旁边显示远程分支的名称
- 突出显示活跃的本地分支
...from this you will be able to determine the remote branch of the current active branch, and more besides.
...由此您将能够确定当前活动分支的远程分支,以及更多。
If you have a lot of local branches, the list may be very long. Use git branch -vv | grep SOMEWORD
to limit the output to only branches containing SOMEWORD. If you can think of a word unique to your branch you'll get the best filter (one result only).
如果您有很多本地分支机构,则列表可能会很长。用于git branch -vv | grep SOMEWORD
将输出限制为仅包含 SOMEWORD 的分支。如果你能想到一个你的分支独有的词,你就会得到最好的过滤器(只有一个结果)。
You will also get some additional data in the output, namely the number (SHA1) and message of the last commit. The grep filter will apply to these to. I couldn't find a way to exclude it.
您还将在输出中获得一些附加数据,即上次提交的编号 (SHA1) 和消息。grep 过滤器将应用于这些。我找不到排除它的方法。
From the Git branch documentation:
从 Git分支文档:
-v
-vv
--verbose
When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well (see also git remote show ).
-v
-vv
--详细
在列表模式下,显示每个头的 sha1 和提交主题行,以及与上游分支的关系(如果有)。如果给出两次,也打印上游分支的名称(另见 git remote show )。
(Based on your comment, yes, it seems that the 'correct' question would ask about the "remote" branch rather than the "parent" branch. But that's what I searched for too! :) )
(根据您的评论,是的,似乎“正确”问题会询问“远程”分支而不是“父”分支。但这也是我搜索的内容!:))