2012-11-23 32 views
2

我已經通過第一副本開始的git的存儲庫,然後「git的承諾」,但是當我做「混帳推」 我收到此錯誤:但它表示「拒絕更新結賬科'?如何修復錯誤時混帳推遭到拒絕

$ git push 
Counting objects: 17, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (13/13), done. 
Writing objects: 100% (13/13), 2.72 KiB, done. 
Total 13 (delta 5), reused 0 (delta 0) 
remote: error: refusing to update checked out branch: refs/heads/master 
remote: error: By default, updating the current branch in a non-bare repository 
remote: error: is denied, because it will make the index and work tree inconsistent 
remote: error: with what you pushed, and will require 'git reset --hard' to match 
remote: error: the work tree to HEAD. 
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to 
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into 
remote: error: its current branch; however, this is not recommended unless you 
remote: error: arranged to update its work tree to match what you pushed in some 
remote: error: other way. 
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set 
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. 
To ssh://[email protected]/home/michae/scripts 
! [remote rejected] master -> master (branch is currently checked out) 

這是什麼意思?

我搜索和閱讀 How to cope with "rejected" on git push?

我甚至嘗試「混帳推起源HEAD」這給了我同樣的錯誤:

回答

3

Git存儲庫有兩種類型:裸露和非裸露。裸倉庫僅包含提交,分支,標籤等;非裸存儲庫還包含當前的工作副本。如果您查看存儲庫,則可以判斷它是否裸露。如果您有一個包含項目中文件的目錄以及一個.git目錄,那麼這是一個非裸存儲庫; .git目錄之外的那些文件是當前的工作副本。如果您只有存儲庫的內容(如refs,objects等),那麼這是一個裸存儲庫。它沒有工作副本。

只能推到裸庫(除非您覆蓋默認配置)。您可以從非裸倉庫中取出,並將其拉入非裸倉庫,但無法將其推入一個倉庫。這是爲了防止更新工作副本的問題。工作副本是您當前狀態的副本;你可能已經編輯過文件,等等。當您拉入存儲庫時,最新的更改將簽出到您的工作副本中;如果您有一些未簽入的本地更改,它們將與您正在從中提取的存儲庫中的更改合併,或者結帳將被拒絕,並且您需要修復本地副本才能查看這些新的變化。

在你推到一個倉庫,你是不是能夠立即進行更改,如果有衝突。工作樹將改爲過時;回購中的內容和工作樹中的內容將不同步。爲了防止這種情況,Git拒絕讓你進入非裸回購。

它建議使用裸回購作爲「中心」的回購,你從那裏推送和拉,使用非裸露的回購協議爲您的工作樹;你實際上在哪裏工作。由於看起來您已經有了一個已經從中克隆的回購商品,因此您需要創建一個裸回購商品,並更新您的origin以指向裸回購商品,而不是非回購商品。您可以使用git clone --bare path/to/original/repo path/to/bare/repo.git創建裸回購(通常將裸回購name.git命名)。如果這將在同一臺計算機上的多個人之間共享,則還應該通過--shared正確設置權限。然後在您的工作副本中運行git remote set-url origin path/to/bare/repo.gitgit remote set-url --push origin path/to/bare/repo.git(或者如果通過SSH訪問它,則爲[email protected]:/path/to/bare/repo.git)。

+0

我做了'git clone --bare path/to/original/repo path/to/bare/repo.git'。但是當我做'git remote set-url origin path/to/bare/repo.git'時,我得到了致命的結果:沒有這樣的遠程'起源' – michael

+0

@michael你有什麼遙控器? 'git remote'顯示了什麼?通常,當您從回購單中克隆時,原始文件被設置爲「原始」,但可能會有所不同。 –

2

目標庫是不是「裸裝」。也就是說,它檢出了文件,而不僅僅是一個.git數據庫。

約定是使用裸'儲存庫'作爲推送的目標。

錯誤消息告訴你,你需要知道的一切:您可以更改配置遠程回購,允許這一點,也可以使其裸露。

1

也許你應該將遙控器轉換爲沒有工作副本的裸回購。

ssh [email protected] 
cd /path/containing/repo 
git clone --bare repo/ repo.git 

現在,在您的工作回購中,編輯.git/config以更新遠程URL。在其末尾添加.git

[remote "origin"] 
    fetch = +refs/heads/*:refs/remotes/origin/* 
    url = [email protected]:/path/to/repo.git 

然後運行

git push origin HEAD 

推動當前分支。