尝试将更改提交到github时出错,致命:远程源已经存在

时间:2015-10-04 11:42:51

标签: git github

我成功创建了远程存储库到GitHub并创建了gh-pages来呈现一些客户端页面,现在我想将更改提交到单个文件但是得到我不理解的错误。 我按照本教程: http://readwrite.com/2013/10/02/github-for-beginners-part-2 并且堆积在这一部分:

  

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

这是我的命令: 检查状态: D:\ dev \ www.foo.com \ Foo \ git \ Foo-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")

指向我想要推送到远程存储库的源(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://fooy@github.com':
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://fooy@github.com':
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.

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

自创建提交以来,删除主数据已提升,因此无法推送您的提交。你可以做几件事:

首先,您可以获取远程更改并在其上重新设置更改:

$ git fetch origin

$ git rebase origin/master

$ git push origin master

其次,如果您拥有远程原点并且100%确定您不希望在那里出现但在分支中没有的更改,则可以强行推送

$ git push --force origin master