实践总结——Git 常见错误及解决方法

Git 是当下最常用的代码管理库,是程序员日常工作中使用频率最高的工具,在频繁的使用过程中,难免会遇到各种各样的问题,今天跟大家分享 Git 常见的错误和解决方法。

实践总结——Git 常见错误及解决方法

问题一:

执行Git add 'somefile'的时候,出现如下错误:

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

解决方法:

rm -f ./.git/index.lock

问题二:

输入git push origin master提示出错信息:

error:failed to push som refs to .......

解决办法:

1)先输入git pull origin master先把远程服务器github上面的文件拉下来

2)再输入git push origin master

3)如果出现报错 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.

4)则需要重新输入git remote add 仓库地址

问题三:

当我们有时候回滚了代码,想强制push到远程仓库的时候,执行git push origin --force会报如下错误:

You are not allowed to force push code to a protected branch on this project

解决办法:

如果用的是gitlab版本库,这说明gitlab对仓库启用了保护,需要在仓库中设置一下:

实践总结——Git 常见错误及解决方法

问题四:

使用 Git 添加远程github仓库的时候提示错误:

fatal: remote origin already exists.

解决方法:

1)先删除远程 Git 仓库

git remote rm origin

2)再添加远程 Git 仓库

git remote add origin 仓库地址

如果执行 git remote rm origin 报错的话,我们可以手动修改gitconfig文件的内容

vi .git/config

把 [remote “origin”] 那一行删掉就好了。

实践总结——Git 常见错误及解决方法

问题五:

切换分支git checkout -b release-1.0,提示报错:

fatal: The current branch release-1.0 has no upstream branch. 
To push the current branch and set the remote as upstream, use

解决方法:

git push --set-upstream origin release-1.0

问题六:

使用git pull代码时,经常会碰到有冲突的情况,提示如下信息:

error: Your local changes to 'c/environ.c' would be overwritten by merge. Aborting.
Please, commit your changes or stash them before you can merge.

解决方法:

这个意思是说更新下来的内容和本地修改的内容有冲突,先提交你的改变或者先将本地修改暂时存储起来。

1)先将本地修改存储起来 ,保存当前工作进度,会把暂存区和工作区的改动保存起来

git stash

2)把远程的文件pull下来

git pull

问题七:

如果输入ssh -T git@github.com出现错误提示:

Permission denied (publickey).

因为新生成的key不能加入ssh就会导致连接不上github。

解决办法:

1)先输入ssh-agent,再输入ssh-add ~/.ssh/id_key,这样就可以了。

2)如果还是不行的话,输入ssh-add ~/.ssh/id_key命令后出现报错Could not open a connection to your authentication agent.解决方法是key用Git Gui的ssh工具生成,这样生成的时候key就直接保存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令行来做。

3)最好检查一下在你复制id_rsa.pub文件的内容时有没有产生多余的空格或空行,有些编辑器会帮你添加这些的。

实践总结——Git 常见错误及解决方法

问题八:

编译ICS时出现如下错误:

build/core/Java.mk:20: *** dalvik/dexgen: Invalid LOCAL_SDK_VERSION '4' Choices are: current . Stop.

解决方法:

rm -rf prebuilt ; repo sync prebuilt

幽你一默

当我试图把一个bug踢给别人的时候....

实践总结——Git 常见错误及解决方法

相关推荐