git登录验证和一些小问题汇总

2021-07-08

Github仓库地址

image-20210628115431843

Azure DevOps仓库地址

image-20210628114919785

image-20210708110009847

http验证

这个比较简单,直接加remote,然后pull(DevOps在执行pull或clone操作时需要凭证,github则不用),执行git push 的时候git bash窗口会弹出来一个账号验证框,输入账号密码即可

image-20210628145553310

image-20210628145637341

image-20210628150623501

保存凭证信息

提交后,当我们再次更新提交时,发现还要我们输入账号密码,这样很不方便,我们先关掉账号密码输入框。执行以下命令

ssh验证

Github和Azure DevOps的使用除了配置那里不一样,其他都是一样的。所以下面的两个配置按照你的需求选其一即可

生成本地公钥密钥

image-20210628112254180

Azure DevOps的配置

image-20210628120714280

image-20210628120739273

image-20210628121217317

Github的配置

image-20210628121709044

image-20210628121809030

image-20210628121949480

从远程仓库获取内容

以github为例,DevOps也是一样的

image-20210628122327067

 

一些问题

fatal: couldn't find remote ref master

远程仓库没有master分支,现在github默认main为主分支,更换分支名称即可

image-20210628144502873

fatal: not a git repository (or any of the parent directories): .git

不是git 仓库,执行git init即可

error: src refspec main does not match any

本地仓库没有main分支,建一个main分支即可。这种情况一般出现在github,现在github默认main为主分支,而git bash 执行git init初始化时,默认分支还是master

image-20210628143906809

error: No such remote: 'main'

没有该远程名称

image-20210628144928226

fatal: 'main' does not appear to be a git repository

没有该远程名称

image-20210628144817723

本地新仓库执行git pull后,Aborting错误

*error: The following untracked working tree files would be overwritten by merge

*Please move or remove them before you merge.

*error: Your local changes to the following files would be overwritten by merge:

*Please commit your changes or stash them before you merge.

本地仓库和远程仓库合并时存在冲突,通常是本地仓库和远程仓库存在同一个文件而导致的问题,如远程仓库中存在test.txt,本地也有test.txt,且这两份test.txt的文件内容不相同

image-20210706152539038

方案一:先暂存(stash)本地,再拉取(pull)远程仓库的内容,然后取出(pop)暂存

image-20210708102049165

方案二:先提交(commit)本地,再拉取(pull)远程仓库的内容

image-20210706153917712

fatal: refusing to merge unrelated histories 拒绝合并无关的历史记录

image-20210706154026074

二进制文件冲突,如何合并?

Automatic merge failed; fix conflicts and then commit the result.

image-20210708103021061

方案一:取消合并

方案二:以某个分支为准,如A、B两个分支冲突,A为本地分支

image-20210708103823247

git高级用法

Git这些高级用法 - 李翰林 - 博客园 (cnblogs.com)