使用git遇到的问题汇总

简介: 1、git中remotes/origin/HEAD指向的分支丢失用git命令查看分支时,会提示一个错误信息:$ git branch -av............error: some refs could not be read查看几个分支都正在使用,用branch -a查看到remotes/origin/HEAD指向了一个不存在的分支:$

1、git中remotes/origin/HEAD指向的分支丢失

用git命令查看分支时,会提示一个错误信息:

$ git branch -av
......
......
error: some refs could not be read

查看几个分支都正在使用,用branch -a查看到remotes/origin/HEAD指向了一个不存在的分支:

$ git branch -a
......
  remotes/origin/HEAD -> origin/demo
......

origin/demo这个分支以前有用过,后来删除掉了,不知道为什么remotes/origin/HEAD会指向这个分支,一般都是指向master分支。

知道问题后,打开 .git/refs/remotes/origin/HEAD 修改demo为master保存。

$ vim .git/refs/remotes/origin/HEAD 

ref: refs/remotes/origin/master

这里写图片描述

这时候再用branch -av就不会报最开始的错误了。

2、Git新建本地分支与远程分支关联问题:git branch –set-upstream-to

git在本地新建分支, push到remote服务器上之后,再次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> dev

问题解析:

git本地新建一个分支后,必须要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。关联目的是如果在本地分支下操作: git pull, git push ,不需要指定在命令行指定远程的分支.推送到远程分支后,你只要没有显示指定,git pull的时候,就会提示你。

解决方法:

使用命令

git branch --set-upstream-to ;

实例如下,其中test为创建的分支

view plaincopy to clipboardprint?
git branch --set-upstream-to test origin/test  

命令的最终修改都是针对config文件。

使用–set-upstream-to去跟踪远程分支。

view plaincopy to clipboardprint?
[core]  repositoryformatversion = 0 filemode = true bare = true logallrefupdates = true[remote "origin"]    fetch = +refs/heads/*:refs/remotes/origin/* url = git@192.168.1.145:android4.4.2_r1.git[branch "master"]    remote = origin merge = refs/heads/master[branch "test"]   remote = origin merge = refs/heads/test[receive]denyCurrentBranch = ignore  

注意仓库.git目录下的config文件

这里写图片描述

后续会添加更多问题。。。

打赏信息:

支付宝

这里写图片描述

微信:

这里写图片描述

相关文章
|
开发工具 git 持续交付
但凡用Git,一定碰到过这些问题!
Git 是目前最流行的版本控制系统,在它的基础之上, GitHub 和 GitLab 成为当前最流行的代码托管平台,它们均提供的代码评审、项目管理、持续集成等功能,越来越多的互联网企业都迁移到 Git。
3805 0
|
网络安全 开发工具 git
git 常用使用及问题记录
1、打开bash,进入工程根目录(引用whaon的话:是和.classpath和.project同级的目录)。PS:我的系统是win7,在bash切换到E的命令是 cd /e; 2、运行 git init 初始化代码仓库(repository) 3、运行git add .
973 0
|
开发工具 git 网络安全
git 常见问题
RPC failed; error: RPC failed; curl 56 SSL read: error:00000000:lib(0):func(0):reason(0), er rno 10054 解决: 应该是pull 内容更新太多,需要设置postBuffer更大些,具体看上面的链接 git config --global http.
1380 0
|
网络安全 开发工具 Android开发
git学习------&gt;"Agent admitted failure to sign using the key." 问题解决方法
今天用git clone 命令clone服务器上的代码时候报了如下的错误: ouyangpeng@oyp-ubuntu:~/Android/git_canplay_code$ git clone gitcply:canplay/vendor/mstar/Canplay/apps/Video Cloning into 'Video'.
1146 0
|
3月前
|
开发工具 git
git 常用命令
这些只是 Git 命令的一部分,Git 还有许多其他命令和选项,可根据具体需求进行深入学习和使用。熟练掌握这些命令能够帮助你更高效地管理代码版本和协作开发。
|
28天前
|
网络安全 开发工具 git
mac git clone命令提示git@gitee.com: Permission denied (publickey).问题修复
mac git clone命令拉取gitee上项目代码时提示密钥问题
|
27天前
|
Java 网络安全 开发工具
Git进阶笔记系列(01)Git核心架构原理 | 常用命令实战集合
通过本文,读者可以深入了解Git的核心概念和实际操作技巧,提升版本管理能力。
|
2月前
|
机器学习/深度学习 Shell 网络安全
【Git】Git 命令参考手册
Git 命令参考手册的扩展部分,包含了从基础操作到高级功能的全面讲解。
74 3

相关实验场景

更多