2014-01-30 247 views
-2

我已經使用git push命令,並且它按照預期工作到目前爲止。在今天測試git命令的時候,我發現推送到HEAD而不是master的工作沒有錯誤,如下所示。 我想了解這兩個命令之間的區別,以便我可以選擇正確的一個。將文件推送到github

# git push origin master 
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts. 
To [email protected]:shan/mobileapp 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to '[email protected]:shan/mobileapp' 
To prevent you from losing history, non-fast-forward updates were rejected 
Merge the remote changes (e.g. 'git pull') before pushing again. See the 
'Note about fast-forwards' section of 'git push --help' for details. 


# git push origin HEAD 
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts. 
Counting objects: 23, done. 
Compressing objects: 100% (18/18), done. 
Writing objects: 100% (19/19), 2.56 KiB, done. 
Total 19 (delta 11), reused 0 (delta 0) 
To [email protected]:shan/mobileapp 
* [new branch]  HEAD -> topic/wip 

其推向頭似乎已經創建的分支稱爲話題/ WIP

我現在可以與主合併分支話題/ WIP。但我會喜歡上面提到的第一個命令按預期工作。而且我不需要創建一個臨時分支來與主人合併。

+2

在試圖推送它之前,您應該在origin/master中合併,如獲得的錯誤消息中所述。 – geoffspear

回答

2

git HEAD基本上是指「當前提交」。所以當你檢出wip分支時,git push origin HEAD相當於git push origin wip,它將推送到遠程分支origin/wip,如果需要的話創建它,如第二個示例所示。

您無法推送給主人的原因是您的本地分支副本已過時。在推送之前,您需要更新您的本地副本:git pull origin master