Git - 常见错误与解决方案

时间:2023-03-09 21:29:46
Git - 常见错误与解决方案

1.windows使用git时出现:warning: LF will be replaced by CRLF

分析: windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示

解决:

 $ rm -rf .git  // 删除.git

 $ git config --global core.autocrlf false  //禁用自动转换 

2.

Git - 常见错误与解决方案

分析: 这是因为没有添加到Git中造成的删除失败, 不在Git的控制之下

解决:

$ git add 1.php

$ git rm -f 1.php

3. 拉取项目需要输入用户名,密码

  我们在git clone工程时有2中形式 https 和git@git。当你使用前者拉取工程时每次都需要输入用户名和密码

解决:

git config --global credential.helper store

这个时候~/.gitconfig文件中会多一行

[credential]
helper = store

4. 文件名称大小写无法进行修改(名称修改了之后,无法进行提交)

  原因: git默认配置为忽略大小写

  解决:

    1) 全局设置

git config core.ignorecase false  //关闭git忽略大小写配置

     2)项目修改

  

. git rm xx 删除本地仓库文件(备份文件)
. 修改文件名称
. git add xx 添加
. git commit -m ''
. git push

5. git push -u origin master    remote: User permission denied

  fatal: unable to access 'http://git.com:11024/lanlang/xs.git/': The requested URL returned error: 403

解决: 设置用户信息并赋予权限

git remote set-url origin https://youruser:password@github.com/user/repo.git

说明: 添加到远程代码库的时候,需要指定用户名,密码
最后执行 git push -u origin master

6. fatal: unable to access 'http://abc@qq.com:abc123456@git.xxx.com/www.git/':

 Couldn't resolve host 'qq.com:abc123456@git.xxx.com'

报错原因是因为用户名包含了@符号,所以需求要把@转码一下

<?php
$userame='abc@qq.com';
echo urlencode($userame);
?>
abc%40qq.com

@符号转码后变成了%40,所以只需在clone时将username变为abc%40qq.com即可,再次执行就ok了。

为了防止密码中也可能会有@,我觉得在拼接之前,可以对用户名和密码分别进行编码操作。

7. Please move or remove them before you can merge

# 删除变化
git clean -d -f

8. 记Git报错-refusing to merge unrelated histories

使用命令:

$git pull origin master --allow-unrelated-histories