鍍金池/ 問(wèn)答/Linux/ 這種push如何做?

這種push如何做?

兩臺(tái)電腦,pc1 pc2.

pc1 push project1 到 https://xxxx@github.com/xxxx/...

git init
git add  project1/
git commit -m "from pc1"  
git remote add origin  ttps://xxxx@github.com/xxxx/yyyy.git
git push -u origin master

成功了。

現(xiàn)在需要將pc2上面的project2 ,push到 https://xxxx@github.com/xxxx/...
下面在pc2上使用相同的代碼

git init
git add  project2/
git commit -m "from pc1"  
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git push -u origin master

報(bào)錯(cuò)

error: failed to push some refs to 'https://xxxx@github.com/xxxx/...'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

代碼修改為

rm -rf .git
git init
git add  project2/
git commit -m "from pc1"  
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git pull
git push -u origin master

報(bào)錯(cuò):
error: failed to push some refs to 'https://xxxx@github.com/xxxx/...'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

代碼繼續(xù)修改為

rm -rf .git
git init
git add  project2/
git commit -m "from pc1"  
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git pull origin master 

報(bào)錯(cuò)


    From https://xxxx@github.com/xxxx/yyyy.git
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

git push -u origin master

報(bào)錯(cuò)

error: failed to push some refs to 'https://xxxx@github.com/xxxx/yyyy.git'

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
請(qǐng)問(wèn),如何解決?

回答
編輯回答
任她鬧
rm -rf .git
git init
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git pull origin master # 這一步,如果提示你有沖突,你要先解決沖突,再往下進(jìn)行
git add  project2/
git commit -m "from pc1"  
git push -u origin master
2017年11月5日 11:28