天天看点

git merge错误:“No commit specified and merge.defaultToUpstream not set”

问题:
           
$ git fetch
$ git merge
           

Now I get the error:

fatal: No commit specified and merge.defaultToUpstream not set.

解决办法:

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.

Personally, I do 

git fetch

 and then 

git merge origin/master

 or 

git pull

 if I have no local commits.

git merge后面需要跟参数,指明是跟的merge的哪个 branch,如git merge origin/master。