你要求我不要告诉我你想合并哪个分支 [英] You asked me to pull without telling me which branch you want to merge with
问题描述
TL; DR:我有一个追踪分支,我不能拉。
所以我在桶-4中:
$ git branch -v
bucket-1 410f7b5 * gh-53 * gh-48 *Share App
bucket-2 7ed70a2 *升级到SOLR 3.3.0
bucket-3 400ffe4 *紧急修复prod issue
* bucket-4 64c2414将分支'bucket-3'合并到bucket-4
master 8dc4854 [提前1] * gh-73
我想从我的遥控器中进行更改:
$ git pull
你问我拉不告诉我你
是哪一个分支想要与
中的'branch.bucket-4.merge'合并,你的配置文件也不会告诉我。请
指定你想在命令行使用哪个分支,
再试一次(例如'git pull< repository>< refspec>')。
有关详细信息,请参阅git-pull(1)。
如果您经常与同一分支合并,您可能希望
在配置文件中使用以下内容:
[branchbucket-4 ]
remote =<昵称>
merge =< remote-ref>
[远程<昵称>]
url =< url>
fetch =< refspec>
有关详细信息,请参阅git-config(1)。
嗯,奇怪,我以为我已经添加了bucket-4作为追踪分支。让我们看看:
$ git remote show origin
* remote origin
抓取网址:git @ github。 com:abcd / main.git
推送URL:git@github.com:abcd / main.git
HEAD分支(远程HEAD不明确,可能是以下之一):
bucket -3
master
远程分支机构:
桶1跟踪
桶2跟踪
桶3跟踪
桶4跟踪
master跟踪
为'git pull'配置的本地分支:
bucket-1与远程bucket-1合并
bucket-2与远程bucket合并
bucket-3与远程bucket-3
主人与远程主人合并
为'git push'配置的本地参考:
bucket-1推到bucket-1(最新)
bucket-2推到第二桶(最新)
第三桶推到第三桶(最新)
第四桶推t o桶-4(本地过期)
主人推动主(快速转发)
<事实上,bucket-4被标记为追踪,但它不知何故被配置为推送,但不是拉取。
查看我的 .git / config
文件,发现我有远程和合并条目对于我的大多数分支机构来说,但不适用于第四桶。如何在没有此功能的情况下追踪?
[remoteorigin]
url = git @ github .com:abcd / main.git
fetch = + refs / heads / *:refs / remotes / origin / *
[branchmaster]
remote = origin
merge = refs / heads / master
[branchrel-2011-07-07]
remote = origin
merge = refs / heads / rel-2011-07-07
[branchbucket-1]
remote = origin
merge = refs / heads / bucket-1
[branchbucket-2]
remote = origin
merge = refs / heads / bucket-2
[branch]
autosetupmerge = true
[branchbucket-3]
remote = origin
merge = refs / heads / bucket-3
我看到这里可能的解决方案是添加 remote / merge
我的配置文件中的bucket-4条目。但是如果没有这个,它是如何被追踪的? bucket-4是在本地创建的,然后从这个repo推送到服务器,所以我怀疑我没有为这个分支设置正确的跟踪。
我可以添加一些配置,以便让所有本地分支机构在将来正确跟踪他们的遥控器? 推送分支时的默认值是将其推送到远程上具有匹配名称的分支。 (请注意,即使本地分支正在跟踪远程跟踪分支,并且远程跟踪分支对应于远程存储库中名称不同的分支,这仍是默认设置。) p>
建立桶-4
和桶-4之间关联的最简单方法
in origin
是为了确保下一次推送时,您可以:
git push -u origin bucket-4
另外,你也可以做:
git branch --set-upstream bucket-4 origin / bucket-4
直接回答几个问题:
在没有此功能的情况下,它甚至会被视为已跟踪?
不是 - 如果没有
branch.bucket-4.merge
或branch.bucket-4,它不会跟踪远程跟踪分支。远程
在你的git配置中。来自git remote show origin
的输出仅显示分支默认推送的位置。
是否可以添加一些配置,以便让所有本地分支机构在将来正确跟踪他们的遥控器? 我不认为有。当您在本地创建
bucket-4
时,我认为发生了这种情况,远程追踪分支不存在,因此无法在此时设置 - 它会是非常混淆的默认行为。您只需要记住将该分支的第一个git push
添加到其上游存储库中-u
p>
我希望这有些帮助。
TL;DR: I have a "tracked" branch that I can't pull.
So here I am in "bucket-4":
$ git branch -v bucket-1 410f7b5 * gh-53 * gh-48 * "Share App" bucket-2 7ed70a2 * upgrade to SOLR 3.3.0 bucket-3 400ffe4 * emergency fix prod issue * bucket-4 64c2414 Merge branch 'bucket-3' into bucket-4 master 8dc4854 [ahead 1] * gh-73
I'd like to pull in changes from my remote:
$ git pull You asked me to pull without telling me which branch you want to merge with, and 'branch.bucket-4.merge' in your configuration file does not tell me, either. Please specify which branch you want to use on the command line and try again (e.g. 'git pull <repository> <refspec>'). See git-pull(1) for details. If you often merge with the same branch, you may want to use something like the following in your configuration file: [branch "bucket-4"] remote = <nickname> merge = <remote-ref> [remote "<nickname>"] url = <url> fetch = <refspec> See git-config(1) for details.
Hmm, odd, I thought I already added "bucket-4" as a tracking branch. Let's see:
$ git remote show origin * remote origin Fetch URL: git@github.com:abcd/main.git Push URL: git@github.com:abcd/main.git HEAD branch (remote HEAD is ambiguous, may be one of the following): bucket-3 master Remote branches: bucket-1 tracked bucket-2 tracked bucket-3 tracked bucket-4 tracked master tracked Local branches configured for 'git pull': bucket-1 merges with remote bucket-1 bucket-2 merges with remote bucket-2 bucket-3 merges with remote bucket-3 master merges with remote master Local refs configured for 'git push': bucket-1 pushes to bucket-1 (up to date) bucket-2 pushes to bucket-2 (up to date) bucket-3 pushes to bucket-3 (up to date) bucket-4 pushes to bucket-4 (local out of date) master pushes to master (fast-forwardable)
Indeed, bucket-4 is marked as "tracked", yet somehow it's configured for push, but not pull.
Looking at my
.git/config
file, I see that I have "remote" and "merge" entries for most of my branches, but not for bucket-4. How is it even considered "tracked" without this?[remote "origin"] url = git@github.com:abcd/main.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "rel-2011-07-07"] remote = origin merge = refs/heads/rel-2011-07-07 [branch "bucket-1"] remote = origin merge = refs/heads/bucket-1 [branch "bucket-2"] remote = origin merge = refs/heads/bucket-2 [branch] autosetupmerge = true [branch "bucket-3"] remote = origin merge = refs/heads/bucket-3
I see that the likely solution here is to add
remote/merge
entries for bucket-4 in my config file. But how is it considered "tracked" without this? bucket-4 was created locally, then pushed to the server from this repo, so I suspect that somehow I didn't set up tracking properly for this branch.Is there some configuration I can add in order to make all local branches track their remotes properly in the future?
解决方案It says
bucket-4 pushes to bucket-4
just because the default when pushing a branch is to push it to one with a matching name on the remote. (Note that this is still the default, even if the local branch is tracking a remote-tracking branch and the remote-tracking branch corresponds to a branch with a different name in the remote repository.)The simplest way to set up the association between your
bucket-4
andbucket-4
inorigin
is to make sure that the next time you push, you do:git push -u origin bucket-4
Alternatively, you can do:
git branch --set-upstream bucket-4 origin/bucket-4
To answer a couple of your questions directly:
How is it even considered "tracked" without this?
In this case it isn't - it's not tracking the remote-tracking branch in any sense if there's no
branch.bucket-4.merge
orbranch.bucket-4.remote
in your git config. The output fromgit remote show origin
is just showing you where the branch would be pushed by default.Is there some configuration I can add in order to make all local branches track their remotes properly in the future?
I don't think that there is. When you created
bucket-4
locally, as I assume happened, the remote-tracking branch didn't exist, so it can't be set up at that point - it would be very confusing default behaviour. You just need to remember to add-u
to your firstgit push
of that branch to its upstream repository.I hope that's of some help.
这篇关于你要求我不要告诉我你想合并哪个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!