git “未指定提交且未设置 merge.defaultToUpstream”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16223561/
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
"No commit specified and merge.defaultToUpstream not set"
提问by John Little
As a new git user, who is an expert with SVN and CVS, I am struggling to get the most basic of git functions to work.
作为一个新的 git 用户,他是 SVN 和 CVS 的专家,我正在努力让最基本的 git 函数工作。
I'm using a shared repo at assembla.com
我在 assembla.com 上使用共享仓库
I created a local clone, and added a file:
我创建了一个本地克隆,并添加了一个文件:
$ git clone repository-url
$ echo "hello" > ha.txt
$ git add -A
$ git commit -a -m "haha"
$ git push
NOTE: at this point I got "No refs in common and none specified; doing nothing" error. After some hours googling, I found the solution was to type this
注意:此时我收到“没有共同的参考,也没有指定;什么都不做”错误。经过几个小时的谷歌搜索,我发现解决方案是输入这个
$ git push origin master
Then I went onto another computer, modified the file, and commit-ed it (surprisingly, I didn't need to do the git push origin magic). Then I back to the main computer, modified it again, so I could see how merge works.
然后我转到另一台计算机,修改文件,并提交它(令人惊讶的是,我不需要执行 git push origin 魔术)。然后我回到主计算机,再次修改它,所以我可以看到合并是如何工作的。
$ git fetch
$ git merge
Now I get the error:
现在我得到错误:
fatal: No commit specified and merge.defaultToUpstream not set.
致命:未指定提交且未设置 merge.defaultToUpstream。
Looking at the man page for "git merge", you have to specify something like this:
查看“git merge”的手册页,您必须指定如下内容:
$ git merge [< commit >..]
The problem is, I cant find out what < commit >
means, and what it should be. E.g. should it be a file, a repo, a message, a version?
问题是,我不知道什么< commit >
意思,它应该是什么。例如,它应该是一个文件、一个存储库、一条消息还是一个版本?
I have not created a branch - I'm just working on the "head" or master as I think git calls it
我还没有创建一个分支——我只是在“头”或主子上工作,因为我认为 git 调用它
Unfortunately, google is not much help on this one. The man pages seem to expect you to know what a < refspec >
, < commit >
and origin
are.
不幸的是,谷歌在这方面没有太大帮助。手册页似乎希望你知道什么是< refspec >
,< commit >
和origin
是。
Any help on this noob problem appreciated.
对这个菜鸟问题的任何帮助表示赞赏。
回答by atamanroman
Usually you do not invoke git merge
without arguments (at least I don't know anyone who does). If you want that merge
defaults to the tracking branch, you need to set merge.defaultToUpstream
to true: git config merge.defaultToUpstream true
. Your master
branch has to track origin/master
in this case: git branch --set-upstream master origin/master
. This is done automagically if origin/master
was already present when you cloned.
通常你不会git merge
在没有参数的情况下调用(至少我不认识任何这样做的人)。如果您希望merge
默认为跟踪分支,则需要设置merge.defaultToUpstream
为 true: git config merge.defaultToUpstream true
。你的master
分支能够跟踪origin/master
在这种情况下:git branch --set-upstream master origin/master
。如果origin/master
克隆时已经存在,这会自动完成。
Personally, I do git fetch
and then git merge origin/master
or git pull
if I have no local commits.
就个人而言,我git fetch
再git merge origin/master
或者git pull
,如果我没有本地提交。
Edit: As VonCmentioned merge.defaultToUpstream
defaults to true
since Git 2.0.
编辑:正如VonC提到的,merge.defaultToUpstream
默认为true
自 Git 2.0 以来。
回答by VonC
Note: if your master
branch is already tracking origin/master
(you can see that with git branch -avvv
, or a longer alias), then a git merge
will not display anymore:
注意:如果您的master
分支已经在跟踪origin/master
(您可以使用git branch -avvv
或更长的别名看到),那么 agit merge
将不再显示:
fatal: No commit specified and merge.defaultToUpstream not set.
The next Git 2.à.x (Q3 2014) will remove that error message:
see commit a01f7f2by Felipe Contreras (felipec
):
下一GIT中2.à.x(Q3 2014)将删除错误消息:
参见提交a01f7f2由菲利普Contreras的(felipec
):
merge
: enable defaulttoupstream
by default
merge
:defaulttoupstream
默认开启
There's no point in this:
这没有任何意义:
% git merge
fatal: No commit specified and merge.defaultToUpstream not set.
We know the most likely scenario is that the user wants to merge the upstream, and if not, he can set
merge.defaultToUpstream
to false.
我们知道最可能的场景是用户想要合并上游,如果没有,他可以设置
merge.defaultToUpstream
为false。
That means you won't need anymore to do a:
这意味着您不再需要执行以下操作:
git config merge.defaultToUpstream true
回答by HonkyTonk
Read Pro Git, it's a very good way to get to know Git.
阅读Pro Git,这是一个非常好的了解 Git 的方式。
It will tell you that your merge
, done with no branch created and with no branch set as merge source, makes no sense.
它会告诉你,你的merge
, 在没有创建分支并且没有分支设置为合并源的情况下完成,没有任何意义。
It will also tell you the difference between git fetch
and git pull
which is important.
它还会告诉您 和 之间的区别git fetch
,git pull
哪个很重要。
Fetching changes does not move your branch, but pulling does.
获取更改不会移动您的分支,但拉动会。
回答by sajin tm
Hope this is a much needed settings after the initial git setup. Set the default branch mapping as a global option,
希望这是初始 git 设置后非常需要的设置。将默认分支映射设置为全局选项,
git config --global merge.defaultToUpstream true
git config --global merge.defaultToUpstream true