44

我有一个场景,在我的本地存储库中有几个必须同步的远程跟踪分支。我们的工作流模型是:

  • 根据所需的远程跟踪分支在本地创建一个分支
  • 做出改变
  • 构建/测试/修复
  • 犯罪
  • 推回远程服务器

我注意到“git status”不会显示我的本地分支基于哪个分支,除非发生了变化;即未提交的本地更改或最近的提取使我的本地分支落后于时代。有什么方法可以知道我的本地分支基于哪个分支,而无需进行更改?像“git status -showparentbranch”或其他一些可以显示这一点的命令。偶尔我会遇到这种需求,但还不知道如何满足它。

4

4 回答 4

54

尝试这个:

git log --graph --decorate
于 2015-10-15T09:09:57.620 回答
19

Git 不跟踪提交通过了哪些分支。没有办法说。如果提交发生在您的仓库中,那么您可以检查 reflog,但仅此而已。看看Pro Git book中对 DAG 的解释- 还在那里阅读了 reflog。

您还可以使用gitk --all或更好地可视化历史记录git log --graph --decorate

希望这可以帮助。

于 2011-06-23T18:05:27.587 回答
13

git branch -vv将要:

  • 列出您所有的本地分支机构
  • 在每个本地分支旁边显示远程分支的名称
  • 突出显示活动的本地分支

...从这里您将能够确定当前活动分支的远程分支,以及更多。

如果您有很多本地分支机构,则列表可能会很长。用于git branch -vv | grep SOMEWORD将输出限制为仅包含 SOMEWORD 的分支。如果你能想到一个对你的分支来说独一无二的词,你会得到最好的过滤器(只有一个结果)。

您还将在输出中获得一些额外的数据,即最后一次提交的编号 (SHA1) 和消息。grep 过滤器将应用于这些。我找不到排除它的方法。

从 Git分支文档

-v

-vv

--详细

在列表模式下,显示每个头的 sha1 和提交主题行,以及与上游分支的关系(如果有)。如果给出两次,也打印上游分支的名称(另见 git remote show )。

(根据您的评论,是的,“正确”问题似乎会询问“远程”分支而不是“父”分支。但这也是我搜索的内容!:))

于 2013-10-25T11:02:35.407 回答
1

there are multiple ways to check that. i have endup with Free way to get this result.

  1. 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.

  2. if you use bitbucket, then they provide view in web to see all your commits for all branchs(By selecting all branch from dropdown).

  3. Free way, via git commnad.

    git log  --graph --decorate --oneline --all
    

    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)

于 2020-09-01T10:27:52.960 回答