1

我在 Michael Hartl 的 Ruby on Rails 教程的第 2 章中,我在命令行中输入了以下内容:

$ git init 
$ git add .
$ git commit -m "Initial commit"
$  git remote add github https://github.com/themaktravels/demo_app.git

fatal: remote github already exists.

$ git push -u github master

Username: 
Password: 

To https://github.com/themaktravels/first_app.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/themaktravels/first_app.git'
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.

我看到在指出 Github 存在之前我遇到了一个致命错误,但我认为这没关系,因为我之前在不同的存储库中提交了 Git。我注意到,当我 时$ git push -u Github master,结果是 git 试图在错误的存储库(first_app.git)而不是新创建的存储库(demo_app.git)中提交。为什么会这样?

在尝试提交之前,我输入了以下内容:

$ cd ~/rails_projects
$ rails new demo_app
$ cd demo_app

然后编辑了我的 gem 文件,一切似乎都很好。直到我遇到这个 git 问题。有什么建议么?谢谢你。

4

3 回答 3

1

问题就在这里:

$  git remote add github https://github.com/themaktravels/demo_app.git

fatal: remote github already exists.

如果您已经有一个名为 的遥控器github,则该git remote add命令不会更改现有设置。用于git remote -v查看您当前的遥控器及其指向的位置。我怀疑您已经有一个github指向https://github.com/themaktravels/first_app.git.

于 2012-11-19T02:14:22.173 回答
1

您已经有一个名为“github”的遥控器,它指向 first_app,因此当您尝试添加指向 demo_app 的新遥控器时,它会失败。

看起来您正试图在已经存在且已经有远程的存储库中初始化 Git。确保在新目录中执行此操作。

于 2012-11-19T02:17:15.023 回答
0

为防止您丢失历史记录,拒绝非快进更新 在再次推送之前合并远程更改(例如“git pull”)。

就像它试图告诉你的那样,推送试图导致非快进更新。

于 2012-11-19T01:57:59.030 回答