2012-11-19 4 views
1

나는 레일 튜토리얼에 마이클 하틀의 루비의 제 2 장에서 오전과 내가 입력 한 명령 줄에 다음과 같은 : 나는 그 Github에서의 존재를 언급하기 전에 치명적인 오류가 발생했습니다 것을보고Git이 잘못된 저장소에 커밋하는 이유는 무엇입니까?

$ 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. 

,하지만 난이 생각 이전에 Git에서 다른 저장소에 커밋했기 때문에 괜찮 았습니다. 내가 $ git push -u Github master 일 때 그 결과는 새로 생성 된 저장소 (demo_app.git)가 아닌 잘못된 저장소 (first_app.git)에서 커밋을 시도하고 있다는 것을 알게되었습니다. 왜 이런 일이 일어나는 걸까요?

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

을 한 후 내 보석 파일을 편집하고 모든 것이 잘 보였다 :

커밋하기 전에, 나는 다음에 입력. 이 자식 문제가 생길 때까지. 어떤 제안? 고맙습니다. 역사를 잃고에서 당신을 방지하기 위해

답변

0

는 비 빨리 감기 업데이트 다시 밀어 전에 원격 변경 (예를 들어, '자식 풀')을 병합 거부했다.

푸시 버튼이 빨리 감기가 아닌 업데이트를 시도하려고합니다.

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

fatal: remote github already exists. 

가 원격 다음 git remote add 명령은 기존의 설정을 변경하지 않습니다, github이라고 이미 한 경우 :

1

문제는 여기에이 비트입니다. 현재의 리모컨과 그들이 가리키는 곳을 보려면 git remote -v을 사용하십시오. https://github.com/themaktravels/first_app.git을 가리키는 github이라는 리모컨이 이미있는 것 같습니다.

+0

필자는'$ git remote -v'를 시도했으며 demo_app.git에 github이있는 것처럼 보입니다 ... 출력은 다음과 같습니다 :'github [email protected] : themaktravels/demo_app.git (fetch)''github \t [email protected] : themaktravels/demo_app.git (push)''출처 \t [email protected] : (가져 오기)''출처 [email protected] : (push)'. 즉, 새 저장소를 만들기 전에 "github"의 이름을 다른 것으로 변경해야합니까? – LearningHowToCode

1

"first_app"를 가리키는 "github"라는 리모컨이 이미 있으므로 demo_app를 가리키는 새 것을 추가하려고하면 실패합니다.

이미 존재하고 이미 원격 저장소가있는 저장소에서 Git을 초기화하려고 한 것 같습니다. 새 디렉토리에서이 작업을 수행해야합니다.

관련 문제