2015-10-04 71 views
1

我成功創建遠程存儲庫到GitHub中,並且還創建了gh頁面以呈現一些客戶端頁面,現在我想將更改提交到單個文件但獲取我不明白的錯誤。 我跟着這個教程: http://readwrite.com/2013/10/02/github-for-beginners-part-2 ,結果被堆放在這一部分:嘗試提交更改爲github時出錯,致命:遠程原點已存在

git remote add origin https://github.com/username/myproject.git

這裏是我的命令: 檢查狀態: d:\ dev的\ www.foo.com \富\ git的\富-html5>獲取狀態 'get'不被識別爲內部或外部命令, 可操作的程序或批處理文件。

D:\dev\www.foo.com\Foo\git\Foo-html5>git status 
# On branch gh-pages 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
#  modified: src/simplegame.js 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

cding到我喜歡推到遠程存儲庫的源(simplegame.js)

D:\dev\www.foo.com\Foo\git\Foo-html5>cd src 

D:\dev\www.foo.com\Foo\git\Foo-html5\src>git add simplegame.js 
warning: LF will be replaced by CRLF in src/simplegame.js. 
The file will have its original line endings in your working directory. 

D:\dev\www.foo.com\Foo\git\Foo-html5\src>git commit -m "www.foo.com Foo v0.1 syntax error" 
[gh-pages warning: LF will be replaced by CRLF in src/simplegame.js. 
The file will have its original line endings in your working directory. 
6959bd7] www.foo.com Foo v0.1 syntax error 
warning: LF will be replaced by CRLF in src/simplegame.js. 
The file will have its original line endings in your working directory. 
1 file changed, 1 insertion(+), 1 deletion(-) 

D:\dev\www.foo.com\Foo\git\Foo-html5\src>git remote add origin https://github.com/fooy/Foo-html5.git 
fatal: remote origin already exists. 

然後即時得到這樣的錯誤: 致命:遠程來源已經存在。

然後我試圖執行這些命令,但仍然錯誤

D:\dev\www.foo.com\Foo\git\Foo-html5\src>git status 
# On branch gh-pages 
nothing to commit (working directory clean) 

D:\dev\www.foo.com\Foo\git\Foo-html5\src>git push origin gh-pages 
Username for 'https://github.com': 
Password for 'https://[email protected]': 
To https://github.com/fooy/Foo-html5.git 
! [rejected]  gh-pages -> gh-pages (non-fast-forward) 
error: failed to push some refs to 'https://github.com/fooy/Foo-html5.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') 
hint: before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

D:\dev\www.foo.com\Foo\git\Foo-html5\src>git push origin master 
Username for 'https://github.com': 
Password for 'https://[email protected]': 
To https://github.com/fooy/Foo-html5.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://github.com/fooy/Foo-html5.git' 
hint: Updates were rejected because a pushed branch tip is behind its remote 
hint: counterpart. Check out this branch and merge the remote changes 
hint: (e.g. 'git pull') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

我到底做錯了什麼?

回答

0

自從您創建了您的提交後,remove master已經進階,因此您的提交無法推送。有幾件事情可以做:

首先,你可以獲取遠程的變化和變基在他們頂部更改:

$ git fetch origin 

$ git rebase origin/master 

$ git push origin master 

其次,如果你擁有遠程的起源和確保你100%不希望出現在那裏但沒有在你的分支的變化,你可以強制推送

$ git push --force origin master 
+0

什麼?我只是想簡單的提交文件..爲什麼我需要重新基地/和做這一切? – user63898

+1

@ user63898:在git中,你並沒有真正提交(單個)文件:每個提交(每個*文件的快照)。因此,如果你與其他人一起工作,你必須選擇新的改變並將它們添加到你的改變中,否則你最近的提交有* un *的副作用 - 他們的工作。 (它比這更復雜,但這就是爲什麼你需要閱讀git教程並瞭解如何使用git完成協作。) – torek

相關問題