Git 似乎不想将本地引用保留到 origin/master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10001514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git doesn't seem to want to keep local refs to origin/master
提问by quodlibetor
First: apologies for the question title, I don't actually know what the problem is so I don't know how to ask about it.
第一:对问题标题表示歉意,我实际上不知道问题是什么,所以我不知道如何提问。
I want to diff my master with upstream master (should be origin/master, based on the way my remotes are set up).
我想将我的 master 与上游 master 进行比较(应该是 origin/master,基于我的遥控器的设置方式)。
But: origin was put there afterI had been working on it locally for a while, so it's "origin" in name only. That is: I had a local repo, put it up into a gitolite setup, and then told my local git to call it origin.
但是:起源是在我在本地工作了一段时间后放在那里的,所以它只是名义上的“起源”。那就是:我有一个本地存储库,将其放入 gitolite 设置中,然后告诉我本地的 git 将其命名为 origin。
These are the symptoms:
这些是症状:
$ git diff master orgin/master
fatal: ambiguous argument 'orgin/master': unknown revision or path not in the working tree.
$ git diff master origin/master --
fatal: bad revision 'origin/master'
Hm.
嗯。
$ git remote -v
origin [email protected]:example (fetch)
origin [email protected]:example (push)
okay, that looks right.
好吧,看起来是对的。
$ git branch -a
... # nothing from origin
Hm.
嗯。
$ git fetch -a origin
From example.com:example
* branch HEAD -> FETCH_HEAD
I have no idea if that's correct. It looks productive, but git diff master origin/master
still fails, and:
我不知道这是否正确。它看起来很有成效,但git diff master origin/master
仍然失败,并且:
$ git branch --track omaster origin/master
fatal: Not a valid object name: 'origin/master'.
Wha?
世界卫生大会?
$ ls .git/refs/remotes
gitps ps
That looks wrong: those are old remotes that haven't existed for months. Also they're empty. And .git/remotes
doesn't exist at all, although I'm not sure that it should.
这看起来不对:那些是几个月不存在的旧遥控器。他们也是空的。并且.git/remotes
根本不存在,尽管我不确定它是否应该存在。
回答by Lily Ballard
Have you tried git remote update
? This will update all remotes, creating remote-tracking branches as needed.
你试过git remote update
吗?这将更新所有遥控器,根据需要创建远程跟踪分支。
回答by chazomaticus
You may need to tell git which branches to fetch from origin. In the .git/config
file for this repo, under the [remote "origin"]
section, there should be a line like fetch = ...
. This tells git what to fetch and where to put it locally. Here's a pretty standard example:
您可能需要告诉 git 从原点获取哪些分支。在.git/config
这个 repo的文件中,在该[remote "origin"]
部分下,应该有一行像fetch = ...
. 这告诉 git 要获取什么以及在本地放置它的位置。这是一个非常标准的例子:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://...
If you don't see the fetch = ...
line, you can safely add it to match the example, which is the standard "track all branches and call them origin/branchlocally" option set up by git clone
.
如果您看不到fetch = ...
线,你可以放心地把它添加到匹配的例子,这是标准的“跟踪所有分支机构,并呼吁他们起源/支本地”选项,通过设立git clone
。
See the git pro bookfor a good description of what's going on.
有关正在发生的事情的详细描述,请参阅git pro book。
回答by Begui
I had a similar issue just now. I discovered that my local .git directory as actually a file
我刚才有一个类似的问题。我发现我的本地 .git 目录实际上是一个文件
$ file .git
.git: ASCII text
I deleted the file, and initialized the git repository
我删除了文件,并初始化了 git 存储库
git init && git remote add origin "gitrepo"
Not too sure why this happened. Hopefully this can help someone..
不太清楚为什么会这样。希望这可以帮助某人..