我怎样才能知道哪个远程“父母”?我的分支是基于什么分支?
我有一个场景,其中我的本地存储库中有几个必须同步的远程跟踪分支。我们的工作流程模型是:
- 根据所需的远程跟踪分支在本地创建一个分支
- 使我们的更改
- 构建/测试/修复
- 提交
- 推送回远程服务器
我注意到“git status”没有显示我的分支除非有什么变化,否则以本地分支为基础;即未提交的本地更改或最近的获取使我的本地分支落后于时代。有没有什么方法可以知道我的本地分支基于哪个分支而无需进行更改?类似“git status -showparentbranch”或其他一些可以显示这一点的命令。有时我会遇到这种需求,但还不知道如何满足它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
试试这个:
try this:
Git 不跟踪提交通过了哪些分支。没有办法说清楚。如果提交发生在您的存储库上,那么您可以检查引用日志,但仅此而已。看看Pro Git 书中对 DAG 的解释 - 还可以阅读在那里重新登录。
您还可以使用 gitk --all 或 git log --graph --decorate 更好地可视化历史记录
希望这会有所帮助。
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.
You can also visualize history better with
gitk --all
orgit log --graph --decorate
Hope this helps.
git Branch -vv
将:...从此您将能够确定当前活动分支的远程分支等等。
如果您有很多本地分支机构,则列表可能会很长。使用 git 分支 -vv | grep SOMEWORD 将输出限制为仅包含 SOMEWORD 的分支。如果您能想到您的分支独有的单词,您将获得最佳过滤器(仅一个结果)。
您还将在输出中获得一些附加数据,即上次提交的编号 (SHA1) 和消息。 grep 过滤器将应用于这些。我找不到排除它的方法。
来自 Git 分支文档:
(根据您的评论,是的,似乎“正确”的问题会询问“远程”分支而不是“父”分支。但这也是我搜索的!:))
git branch -vv
will:...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).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.
From the Git branch documentation:
(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! :) )
有多种方法可以检查这一点。我最终以免费的方式获得了这个结果。
使用 gitkraken(付费私人存储库!),它为您提供了查看分支和提交树的绝佳方式。通过向下滚动,您将到达父分支的根部。
如果您使用 bitbucket,那么它们会在网络中提供视图,以查看您对所有分支的所有提交(通过从下拉列表中选择所有分支)。
免费方式,通过 git commnad。
命令说明
git log 查看日志。
--graph以图表形式查看日志。
--装饰以创辉模式查看日志。
--oneline查看日志,仅一行,未提交完整详细信息。
--全部查看日志,所有分支。 (解决此问题很重要)
there are multiple ways to check that. i have endup with Free way to get this result.
use gitkraken(paid for private repository!), it provide you wonderfull way to see Tree of your branchs and commits. by scolling down you will reach root of your parent branch.
if you use bitbucket, then they provide view in web to see all your commits for all branchs(By selecting all branch from dropdown).
Free way, via git commnad.
Commnad Expaination
git log view log.
--graph view log as graph.
--decorate view log in colorfull mode.
--oneline view log, row only one line not full detail in commits.
--all view log, all branchs. (important to solve this thread)
这是查看当前分支的父分支的命令
Here is a command to see the parent branch of your current branch
这是 Arpit 的答案的副本,但有解释。
该命令链用于查找不是当前分支的最新分支。让我们一步步分解:
git show-branch -a
:grep '\*'
:*
) 的行。在 git show-branch 中,星号表示当前分支或包含提交的分支。grep -v \
git rev-parse --abbrev-ref HEAD``:git rev-parse --abbrev-ref HEAD
返回当前分支的名称,grep -v
排除与此名称匹配的行。头-n1
:sed 's/.*\[\(.*\)\].*/\1/'
:sed
(流编辑器)从行中提取分支名称。该模式匹配方括号 ([...]
) 之间的所有内容并捕获它。sed 's/[\^~].*//'
:^
或~
后面的任何字符。这些字符在 Git 中用于引用提交的祖先(例如,branch^
是分支尖端的父级,branch~1
是第一个祖先,等等.).This is a copy of Arpit's answer but with an explanation.
This command chain is used to find the most recent branch that is not the current branch. Let's break it down step-by-step:
git show-branch -a
:grep '\*'
:*
). Ingit show-branch
, the asterisk indicates the current branch or a branch that contains the commit.grep -v \
git rev-parse --abbrev-ref HEAD``:git rev-parse --abbrev-ref HEAD
returns the name of the current branch, andgrep -v
excludes lines that match this name.head -n1
:sed 's/.*\[\(.*\)\].*/\1/'
:sed
(stream editor) to extract the branch name from the line. The pattern matches everything between square brackets ([...]
) and captures it.sed 's/[\^~].*//'
:^
or~
. These characters are used in Git to refer to ancestors of commits (e.g.,branch^
is the parent of the tip of the branch,branch~1
is the first ancestor, etc.).一个也许更简单(最近)的替代方案(我的):https://stackoverflow.com/a/79132926/2039709
A perhaps simpler (recent) alternative (mine): https://stackoverflow.com/a/79132926/2039709