云效git问题和处理

小知识 01-20 13:43

先在阿里云云效上新建了一个项目,然后复制git地址,本地新建一个文件夹,复制需要上传的源代码到新建的文件夹里面。点击鼠标右键,选择列表中的Git Bash Here(或者自主使用cmd进入当前目录)

1、git init
2、git clone 项目的git地址

然后根据提示,输入项目设置的账号和密码。

3、git status
4、git add .
5、git commit -m '初始化'
6、git push

到了第6步的时候报错了。原来是因为我自己建的项目,是master身份,所以最后一句命令的远程分支名就写了master,具体应情况而定

解决办法:
6、git remote add origin '项目的git地址'
7、git push -u origin master

git push -u origin master

上面正常的流程能解决,但下面有种情况是我先在阿里云的控制台有新建了一个文件,本地没有先pull。然后在6、git pull里出现了报错

一、更新项目出现There is no tracking information for the current branch. Please specify which branch you...

当出现上面的情况时,我们可以有两种解决方法,就比如说要操作master吧,一种是直接指定远程master:

git pull origin master

另外一种方法就是先指定本地master到远程的master,然后再去pull:

6、git branch --set-upstream-to=origin/master master
7、git pull

这样就不会再出现“There is no tracking information for the current branch”这样的提示了。

二、出现 Git :fatal: refusing to merge unrelated histories解决

 Git :fatal: refusing to merge unrelated histories

上网查到原因是两个分支是两个不同的版本,具有不同的提交历史。解决方法:

6、git pull origin master --allow-unrelated-histories

可以允许不相关历史提,强制合并,确实解决了这个问题。在git remote add origin '项目的git地址'的过程中,又犯了一个错误, 项目的git地址之前是用https来,在这里操作时写成 git@XXX 的地址, 在 git push -u origin master 里又提示 fatal: remote origin already exists 错误。真是一波三折啊。最后找到解决办法如下:

三、出现fatal: remote origin already exists 错误

fatal: remote origin already exists

git remote rm origin  然后再重新添加  git remote add origin '项目的git地址'  解决问题。没想到最后又出现问题了。在 git pull 的时候提示 Updates were rejected because the tip of your current branch is behind。

四、错误 Updates were rejected because the tip of your current branch is behind。

出现这个错误的原因是git本地仓库的当前版本低于远程仓库的版本(大白话就是:你在github上进行的修改没有同步到本地git仓库中)。累了累了。因为是一个人开发的,直接用狠的指令来操作。 git pull -u origin master -f 啊,牛逼!哈哈,直接强制更新。 但是这样是不对的。后果是远程仓库的其它人员的修改没有了。多人协作时一定不要这样搞。个人嘛爽!