Android Studio 使用 git 遇到的问题

xiaoxiao2021-02-28  60

1. 无法commit

因为会检查代码,就算没有错误,只有警告它也会让你无法提交。不会像单个文件的提交一样,提示你选择Review还是继续commit。所以就取消提交页面的“Perform code analysis”选项 

2. 无法push推送

现象:  Push的时候,弹出错误信息:Push rejected,Push to origin/master was rejected 

 

控制台输出的详细错误信息: 

原因:  通过上述错误信息,告诉我们github中有我们本地没有的文件,需要先pull。在VCS —— Git —— Pull 

Pull也会报错:Git Pull Failed,fatal: refusing to merge unrelated histories 

也就是说直接pull也是不行的。并提示拒绝合并两个不相关的仓库

解决办法:  打开Git Bush。本地资源管理器的工程目录下,右键——Git Bush Here。或直接打开Git Bash,然后用cd命令打开工程目录。  输入命令:git pull origin master --allow-unrelated-histories  表示允许不相关的仓库合并。    此时,你可以看到工程中多了两个github中的两个文件 

其中.gitignore文件是还没有添加的,需要添加然后提交。  添加命令:git add .gitignore  提交命令:git commit 

添加后提交,会弹出提交的提示信息:    这里是VIM文本编辑器让你提交。操作命令:  进入到输入状态:按i键  从输入状态退出:Esc键 —— Shift+;键 —— wq!(保存并退出)或q!(不保存退出) —— Enter

最后使用提交,命令:git push –u origin master    上面信息代表上传成功,去github看看就知道了。

此问题困扰了我很久才解决,最主要的就是这条命令:  git pull origin master --allow-unrelated-histories  其他的命令都可以在界面上操作。  参考:http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories

3. 取消工程与Git的关联

在本地项目工程下有一个.git文件夹,删除即可。

4.更新出错

Can't update: no tracked branch

No tracked branch configured for branchmaster. To make your branch track a remote branch call, for example, Git branch --set-upstream master origin/master

解决办法:输入以下命令

git branch --set-upstream master origin/master

转载请注明原文地址: https://www.6miu.com/read-78103.html

最新回复(0)