2015-03-02 87 views
3

我在git中爲零。絕對零度。所以網上有很多材料和提示,但是我不能把它們放在一起。Git本地庫所有步驟

所以有人可以告訴我我做錯了什麼,還有什麼我應該做的,以實現我在找什麼?

我想要做的事很簡單。我已經使用C++編寫了一個項目,現在我想創建一個本地存儲庫來對我的所有更改進行版本控制。這就是我需要的。

我有一個文件夾:

~/myproject 

其中包含我的項目文件。而另一個文件夾來保存裏面(我本地的地方保存的更改)

~/my-local-repository 

所以,首先,我建立了一個回購:

cd ~/myproject 
git init 

然後我創建了一個的.gitignore:

cd ~/myproject 
touch .git/.gitignore 

並排除我的bin目錄。

然後我加了幾個文件

git add this that 

然後我把他們趕走

git reset 

,並再次增加了一些文件。我改變了一些文件,並承諾:

git commit -am "new change" 

然後設定虛擬用戶名和電子郵件:

git config user.name "my.phd" 
git config user.email [email protected] 

然後我設置爲本地更改本地資源庫中的文件夾:

git remote add local ~/my-local-repository 

所以我希望我所有的改變都在這裏。

現在,當我推:

git push local 

我得到這個錯誤:

warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 

    git config --global push.default matching 

To squelch this message and adopt the new behavior now, use: 

    git config --global push.default simple 

When push.default is set to 'matching', git will push local branches 
to the remote branches that already exist with the same name. 

In Git 2.0, Git will default to the more conservative 'simple' 
behavior, which only pushes the current branch to the corresponding 
remote branch that 'git pull' uses to update the current branch. 

See 'git help config' and search for 'push.default' for further information. 
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 
'current' instead of 'simple' if you sometimes use older versions of Git) 

fatal: '/media/doc/my-local-repository' does not appear to be a git repository 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

也許這個錯誤是很多人非常簡單。但我對此一無所知。我到現在爲止做了什麼錯誤以及如何解決?

+0

[Warning:push.default is unset;其隱含的價值正在改變Git 2.0](http://stackoverflow.com/questions/13148066/warning-push-default-is-unset-its-implicit-value-is-changing-in-git-2-0) – 2015-03-02 14:22:14

+0

@ Pierre-Jean我不明白解決方案 – ar2015 2015-03-02 14:24:42

+0

@ Pierre-Jean,另一個鏈接解決警告,但不是致命的錯誤。 – tom 2015-03-02 14:25:14

回答

1

的錯誤就行了

'/media/doc/my-local-repository' does not appear to be a git repository 

該文件夾並沒有在它混帳回購協議。您需要運行

git init 

其中。如果你在一個新的本地分公司工作,你還必須將這個新的分支向上遊推送,以使它出現在遠端。要做到這一點,請參閱this問題。

+0

只是想確保。 'git init'必須在源代碼文件夾或存儲文件夾上運行? – ar2015 2015-03-02 14:26:11

+0

@ ar2015:兩者。這兩個文件夾都需要git倉庫 – tom 2015-03-02 14:26:52

+0

我在兩者上都這樣做了。這次我得到這個錯誤 '沒有共同的和沒有指定的參考;什麼也不做。 也許你應該指定一個分支,比如'master'。 致命:遠程端意外掛斷 錯誤:無法將某些文件推送到'/ media/doc/my-local-repository' – ar2015 2015-03-02 14:31:50

0

git push local master(或,而不是master,你要推的分支)

如果你只在其他回購確實git init,它沒有分支呢。所以,沒有分支可以跟蹤(只允許git push local)。

執行此命令後,最後不需要master,因爲master現在存在於local

+0

謝謝。這次我得到了這個[message](http://pastebin.com/sfmHj2it) – ar2015 2015-03-02 14:35:03

+0

我應該用'git init --bare'嗎? – ar2015 2015-03-02 14:48:49

+0

建議(但不強制)只有裸露的存儲庫接受推送。日誌告訴你如何去做。但我建議只推送到裸存儲庫(使用'git init --bare'創建)。 – 2015-03-02 16:14:12