How can I tell which remote “parent” branch my branch is based on?

大城市里の小女人 提交于 2019-12-02 17:04:15
elrrrrrrr

try this:

git log --graph --decorate
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.

You can also visualize history better with gitk --all or git log --graph --decorate

Hope this helps.

git branch -vv will:

  • list all your 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).

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:

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

(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! :) )

You could also give this a try:

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

And using this alias in your .gitconfig file:

[alias]
    showparentbranch = rev-parse --abbrev-ref --symbolic-full-name @{u}

You could then simply call:

git showparentbranch

Tested on git version 2.10.2.windows.1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!