git 常见问题

git pull 提示 refusing to merge unrelated histories

解决方法:git pull --allow-unrelated-histories  < 回车后会进入编辑页面,一般直接 q 退出即可 >

或使用 : git pull origin master --allow-unrelated-histories 

如果上述命令错可以使用下面命令:

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

如果你是git pull或者git push报fatal: refusing to merge unrelated histories
同理:
git pull origin master --allow-unrelated-histories / git pull --allow-unrelated-histories

 

git push时报了这个错:fatal: unable to access 'https://github.com/.......': OpenSSL SSL_read: Connection was reset, errno 10054

取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

取消 ssl 验证
git config --global http.sslVerify "false"

有时是网络问题,等待一会在重新连接,在push

 

To push the current branch and set the remote as upstream,意思是推送当前分支并将远程设置为上游

解决方法:git push --set-upstream origin master

git branch --set-upstream-to=origin/<branch> master

Git在本地新建分支后,必须要做远程分支关联。关联目的是如果在本地分支下进行git pull 和 git push操作时 ,不需要指定在命令行指定远程的分支. 推送到远程分支时,没有关联的情况下而且没有指定, git pull 的时候,就会提示你如下信息

MacBook-Pro:projects user$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

解决方法:git branch --set-upstream-to=origin/master master 

如果本地分支与远程分支同名可以:git branch --set-upstream-to=origin/master

不带任何参数的git push,默认只推送当前分支。第一次提交时可以使用 git push -u origin master 将本地的master分支推送到origin主机,同时指定origin为默认主机(建立关联关系),后面就可以不加任何参数使用git push了。

 

使用git提交到github,每次都要输入用户名和密码的解决方法

原因:在clone 项目的时候,默认使用了 https方式,而不是ssh方式。

查看clone 地址:git remote -v,重新添加项目

git remote rm origin
git remote add origin git@gitee.com:username/repository.git
git push -u origin master

 

git warning: LF will be replaced by CRLF in 解决办法

首先问题出在不同操作系统所使用的换行符是不一样的,下面罗列一下三大主流操作系统的换行符:

Uinx/Linux采用换行符LF表示下一行(LF:LineFeed,中文意思是换行);

Dos和Windows采用回车+换行CRLF表示下一行(CRLF:CarriageReturn LineFeed,中文意思是回车换行);

Mac OS采用回车CR表示下一行(CR:CarriageReturn,中文意思是回车)。 

在Git中,可以通过以下命令来显示当前你的Git中采取哪种对待换行符的方式

  $ git config core.autocrlf

此命令会有三个选项,“true”,“false”或者“input”

为true时,Git会将你add的所有文件视为文本问价你,将结尾的CRLF转换为LF,而checkout时会再将文件的LF格式转为CRLF格式。

为false时,line endings不做任何改变,文本文件保持其原来的样子。

为input时,add时Git会把CRLF转换为LF,而check时仍旧为LF,所以Windows操作系统不建议设置此值

git config --global core.autocrlf false  // 命令行设置禁止自动转换

注意事项:

将core.autocrlf设为false即可解决这个问题,不过如果你和你的伙伴只工作于Windows平台或者Linux平台,那么没问题,不过如果是存在跨平台的现象的话,还是需要考虑一下。

但当 core autocrlf为true时,还有一个需要慎重的地方,当你上传一个二进制文件,Git可能会将二进制文件误以为是文本文件,从而也会修改你的二进制文件,从而产生隐患。

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/CasPHP (master)
$ git push
git@github.com: Permission denied (publickey).// 权限被拒绝(publickey)
fatal: Could not read from remote repository. //无法从远程存储库读取

Please make sure you have the correct access rights  and the repository exists.  //请确保您拥有正确的访问权限并且存储库存在。

 

如果合并时(git pull | git merge)warning: LF will be replaced by CRLF in ……

解决方法:
git config --global core.autocrlf false
就可以解决了。
原因就是:
原因是路径中存在 / 的符号转义问题,false就是不转换符号默认是true,相当于把路径的 / 符号进行转义,这样添加的时候就有问题

 

创建分支时fatal: Not a valid object name: 'master'

原因:本地还没有创建master
解决方案:添加一个文件提交即可

 

处理 :untracked files

1. # 删除 untracked files

git rm -r --cache 文件名
#撤销添加到暂存区里的文件

git rm -f 文件名 #删除暂存区和工作区的文件

git clean -f #删除文件

# 连 untracked 的目录也一起删掉
git clean -fd

# 连 gitignore 的untrack 文件/目录也一起删掉 (慎用,一般这个是用来删掉编译出来的 .o之类的文件用的)
git clean -xfd

# 在用上述 git clean 前,墙裂建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删
git clean -nxfd
git clean -nf
git clean -nfd

2 .#版本回退

git reset --hard HEAD # 回退上一个版本
git reset --hard 3628164 # 回退到指定版本 使用 git log 查看版本库

3. #添加 git 忽略文件

在仓库目录下新建一个名为.gitignore的文件

 

remote: Support for password authentication was removed on August 13, 2021

 在git 官网个人设置页面,找到 

Settings -->

Developer settings -->

选择个人访问令牌 Personal access tokens, --->

然后点击生成令牌 Generate new token --->

设置 token 的有效期,访问权限等 --->

生成令牌 Generate token --->

最后,把 token 直接添加远程仓库链接中,这样就可以避免同一个仓库每次提交代码都要输入 token

git remote set-url origin https://<your_token>@github.com/<uasename>/<repo>.git

<your_token> 换成刚才生成的 token
<username> 换成你的用户名
<repo> 换成你的仓库名 例如:xueyuan.git

 

git 命令行界面乱码

文件提交编码格式 :  git config --global i18n.commitencoding utf-8 

这个主要就是log输出的编码格式: git config --global i18n.logoutputencoding utf-8 

界面编码格式: git config --global gui.encoding utf-8 

设置status编码: git config --global core.quotepath false 

设置gui编码: git config --global gui.encoding utf-8 

commit 编码: git config --global i18n.commit.encoding utf-8 

log 编码: git config --global i18n.logoutputencoding utf-8 

 

posted @ 2018-10-14 11:55  柔和的天空  阅读(321)  评论(0编辑  收藏  举报