如何查找分支是本地跟踪的分支还是用户创建的本地分支? [英] How to find if a branch is a locally tracked branch or user created local branch?

查看:220
本文介绍了如何查找分支是本地跟踪的分支还是用户创建的本地分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用'git branch -b branch-name origin / branch-name'在本地存储库本地跟踪了一个远程跟踪分支。
我的远程分支是test2 / test2(origin / branch-name),它在本地作为test2进行跟踪。



原点也被命名为test2。
我没有签出我的本地跟踪分支test2。



当我做'git pull origin remote-branch:local-tracked-branch'我得到这个错误
$ b $ [test2] $ git pull test2 test2:test2
从/ gitvobs / git_bare / test2
!当我检查我的本地跟踪分支test2
并且拉'git pull origin local-tracked'时,[test2 - > test2(非快进)

-branch'我没有收到错误
,并且我使用'git pull test2 test2'进行了一次拉取。



从/ gitvobs / git_bare / test2
* branch test2 - > FETCH_HEAD
自动合并a.txt
自动合并失败;修复冲突,然后提交结果。



我知道添加+(git pull test2 + test2:test2)会有帮助,但它会覆盖本地更改。



那么我怎么知道我的本地分支是由我在本地使用'git branch new-branch-name'创建的还是本地从远程分支使用git branch -b branch-name原始/分支名称'?

解决方案

独立于追踪分支列表(您可以使用 git config -l <​​/ code>),一个非快进消息意味着无法合并分支中的远程分支(即远程分支提取的提交的本地副本),因为:




  • 你的分支有自己的提交

  • 远程分支自上次提交后有新提交



  • $ b

    所以:

      --last pull 
    |
    v
    xxxxx< - test2
    \
    --yyy< - test2 / test2

    鉴于这将是一个快速合并

      --last pull 
    |
    v
    xx< - test2
    \
    --yyy< - test2 / test2

    所以:

      git checkout test2 
    git fetch test2 test2
    git merge test2 / test2
    #fix冲突
    git commit

    请,请打电话给您的远程回购除test2以外的任何其他名称。这是太多的test2在这里;)






    现在查看本地仓库中跟踪的远程分支列表: p>

      git config --get-regexp分支.. * 


    I have a remote tracking branch tracked locally in my local repository using 'git branch -b branch-name origin/branch-name'. My remote branch is test2/test2 (origin/branch-name) which is being tracked locally as test2.

    The origin is also named test2. I haven't checked-out my local tracking branch test2.

    When i do a 'git pull origin remote-branch:local-tracked-branch' i get this error

    [test2]$ git pull test2 test2:test2 From /gitvobs/git_bare/test2 ! [rejected] test2 -> test2 (non fast forward)

    Whereas when i checkout my local tracking branch test2 and do pull 'git pull origin local-tracked-branch' i don't get the error and i do a pull using 'git pull test2 test2'

    From /gitvobs/git_bare/test2 * branch test2 -> FETCH_HEAD Auto-merging a.txt Automatic merge failed; fix conflicts and then commit the result.

    i know that adding a + (git pull test2 +test2:test2) would help but it overwrites local changes.

    So how do i know which of my local branches are created by me locally using 'git branch new-branch-name' or tracked locally from remote branches using git branch -b branch-name origin/branch-name'?

    解决方案

    Independently of the list of tracked branched (which you can see with git config -l), a "non-fast-forward" message means cannot merge the remote branch (i.e. the local copy of the fetched commit of the remote branch) in your branch because:

    • your branch has commits of its own
    • the remote branch has new commits since the last pull

    so:

      --last pull
      |
      v
    x-x-x-x-x <--test2
      \
       -y-y-y <-- test2/test2
    

    Whereas this would have been a fast-forward merge

      --last pull
      |
      v
    x-x <--test2
      \
       -y-y-y <-- test2/test2
    

    So:

    git checkout test2
    git fetch test2 test2 
    git merge test2/test2
    #fix conflicts
    git commit
    

    And please, do call your remote repo any other name than test2. That is way too many test2 here ;)


    Now for the list of remote branches tracked in your local repo:

    git config --get-regexp branch..*
    

    这篇关于如何查找分支是本地跟踪的分支还是用户创建的本地分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆