git常见问题解决方式
问题一:git commit提示fatal: Unable to create index.lock File exists
报错内容:
$ git commit -m 'Test'
fatal: Unable to create 'D:/MyProject/.git/index.lock': File exists.
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.
解决方案:
在项目根目录下找到 .git 文件夹。打开该文件夹。找到文件夹里面的index.lock 文件,将其删除,即可解决问题(如果提示不能删除文件,就重启系统)。
表现形式:
提交后更改数为0,修改了文件后点击保存,更改数就会变成无。形成一种脱机现象,文件修改无效,也无法上传。
产生原因:
应该是由于git操作的时候修改了一些文件导致的操作冲突被锁住了。
问题二:git pull提示There is no tracking information for the current branch
报错内容:
git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
解决方案:
方案一:比如说操作master,在pull时直接指定远程master:
git pull origin master
方案二:比如操作master,可以先在指定本地master到远程master,然后再去pull:
git branch --set-upstream-to-origin/master master
git pull
产生原因:
是因为本地分支和远程分支没有建立联系(使用git branch -vv
可以查看本地分支和远程分支的关联关系)。
问题三:git clone提示Filename too long
报错内容:
git clone git@xxxx.git
......
error:unable to create file xxxx : Filename too long
fatal:unable to checkout working tree
warning:Clone succeeded,butcheckout failed
You can inspect what was checked out with ‘git status’ and retry the checkout with ‘git checkout -f HEAD’
......
解决方案:
在git bash中,运行下列命令: git config --global core.longpaths true
就可以解决该问题。
--global是该参数的使用范围,如果只想对本版本库设置该参数,只要在上述命令中去掉–global即可。
然后在执行 git checkou -f HEAD
命令即可继续完成clone远程仓库项目。
git config --global core.longpaths true
git checkou -f HEAD
产生原因:
git是可以支持创建4096长度的文件名,上诉问题在Unix系统和Mac系统中是不会出现的,这是在Windows系统中调用旧的api,支持长度260长度的文件名。允许较长的文件名这个设置在Windows系统中默认是关闭的。