1、不允许将代码推送到该项目上受保护的分支

- 问题发生:

remote: GitLab: You are not allowed to push code to protected branches on this project.
To https://git.lianjingkeji.com/backend/trade.git! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.lianjingkeji.com/backend/trade.git'

- 问题原因:
该分支为受保护分支,用户没有权限推送代码到这个分支。

- 解决方案:

1. 解决方法一:修改提交代码人员角色

进入代码仓库详情页,单击“成员列表”页签,搜索目标用户,修改成员为主程或以上管理权限角色

2. 解决方法二:修改分支保护设置

进入代码仓库详情页,选择“设置 > 仓库管理 > 保护分支管理”,解除对该分支的保护。

2、代码拉取失败

- 问题发生:

用git pull来更新代码,遇到了下面的问题:

# git pull
Updating fc1d61e..e4f2867
error: Your local changes to the following files would be overwritten by merge:main.go
Please, commit your changes or stash them before you can merge.
Aborting

- 问题原因:

团队其他成员修改了某文件并已提交入库,你在pull之前修改了本地该文件,等你修改完代码再pull时,这时会报错如下错误:

- 解决方案:

1. 解决方法一:保留修改

执行以下三条命令git stash #封存修改
git pull origin master
git stash pop #把修改还原

注:

git stash:备份当前工作区内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前工作区内容保存到Git栈中

git pull:拉取服务器上当前分支代码

git stash pop:从Git栈中读取最近一次保存的内容,恢复工作区相关内容。同时,用户可能进行多次stash操作,需要保证后stash的最先被取到,所以用栈(先进后出)来管理;pop取栈顶的内容并恢复

git stash list:显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。

git stash clear:清空Git栈

2. 解决方法二:废弃修改:

核心思想就是版本回退,具体命令如下

git reset --hard
git pull origin master

注:不建议使用第二种。除非你再三确定不需要本地的修改了。

3、电子邮箱未配置

- 问题描述:

使用git控制代码版本时,出现如下无法检测到邮箱的错误

# git stash*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity.
Omit --global to set the identity only in this repository.fatal: unable to auto-detect email address (got 'root@ljkj-dev-00.(none)')
Cannot save the current index state

- 问题原因:

因为我们没有在 git 中分配我们的用户名和电子邮件 ID,所以我们要做的是在 git 中分配它

- 解决方案:

配置你的github用户名和和邮箱,邮箱是你github的注册邮箱,用户名是你github的用户名

git config --global user.email "lijie@163.com"
git config --global user.name "lijie"

再次运行,成功

4、git add 警告

- 问题描述:

git add:添加至暂存区,但并未提交至服务器。git add . 是表示把当前目录下的所有更新添加至暂存区。有时在终端操作这个会提示:

warning: LF will be replaced by CRLF in xxxx(需要提交的文件名).
The file will have its original line endings in your working directory

- 问题原因:

这是因为文件中换行符的差别导致的。这个提示的意思是说:会把windows格式(CRLF(也就是回车换行))转换成Unix格式(LF),这些是转换文件格式的警告,不影响使用。
git默认支持LF。windows commit代码时git会把CRLF转LF,update代码时LF换CRLF。

此时只需要执行如下代码:

git rm -r --cached .
git config core.autocrlf false
git add .

或者在Gitshell中输入如下命令解决:

git config --global core.autocrlf false

使用以下命令查看Git所有配置。

git config --list

5、提交代码分支错误

- 问题描述:

当我们在github上传创建仓库以后默认生成的页面提示我们的是推送到main分支。

error: src refspec main does not match any
error: failed to push some refs to

- 问题原因:
但是实际我们创建的项目是在master分支下面。我们只要
把git push orgin main改成git push origin master就好了。

6、提交代码分支错误

- 问题描述:

使用 github 打 tag 的时候失败,错误提示为

We weren’t able to create the release for you. Make sure you have a valid tag.

- 解决方案:

需要先手动创建,再进行输入,就可以成功打tag

7、存在隐藏文件夹

- 问题描述:

提交代码时,报错有文件未提交

$ git add .
error: 'lijie/' does not have a commit checked out
fatal: adding files failed

- 解决方案:

原因是出现了一个隐藏文件夹lijie/ 在你的项目文件夹中找到并且删除,就OK啦

日常开发中,你需要掌握的git使用报错解决相关推荐

  1. git使用报错:fatal: Couldn't find remote ref master的解决方法

    git使用报错:fatal: Couldn't find remote ref master的解决方法 fatal: Couldn't find remote ref master 翻译过来就是:致命 ...

  2. git使用报错: fatal: Couldn‘t find remote ref master的解决方法

    git使用报错: fatal: Couldn't find remote ref master的解决方法 参考文章: (1)git使用报错: fatal: Couldn't find remote r ...

  3. git使用报错:fatal: Couldn‘t find remote ref master的解决方法

    git使用报错:fatal: Couldn't find remote ref master的解决方法 参考文章: (1)git使用报错:fatal: Couldn't find remote ref ...

  4. git使用报错:Cannot lock

    问题一:Cannot lock XXX\.git\index Cannot lock 解决方法:删除当前项目中.git目录中的index.lock文件即可(.git目录是隐藏目录) 问题二:解决同一个 ...

  5. 【错误记录】Git 使用报错 ( git branch -a 仍能查询到已经删除的远程分支 )

    文章目录 一.报错信息 二.解决方案 一.报错信息 之前已经执行 git push origin --delete feature1 命令 , 删除了 feature1 远程分支 , 删除操作成功 , ...

  6. 【错误记录】Git 使用报错 ( git: ‘switch‘ is not a git command. See ‘git --help‘. )

    文章目录 一.报错信息 二.解决方案 一.报错信息 执行 git switch -c feature1 命令 , 创建分支 , 报如下错误 : D:\Git\git-learning-course&g ...

  7. 【错误记录】Git 使用报错 ( no changes added to commit (use “git add“ and/or “git commit -a“) )

    文章目录 一.报错信息 二.解决方案 一.报错信息 修改了 Git 版本库中的 file1.txt 文件 , 直接执行 git commit -m "modify file1" 命 ...

  8. 【错误记录】Git 使用报错 ( error: The branch ‘feature1‘ is not fully merged. )

    文章目录 一.报错信息 二.解决方案 一.报错信息 执行 git branch -d feature1 命令 , 删除 feature1 分支 , 报如下错误 : D:\Git\git-learnin ...

  9. 【错误记录】Git 使用报错 ( error: Cannot delete branch ‘dev‘ checked out at ‘D:/Git/git-learning-course‘)

    文章目录 一.报错信息 二.解决方案 一.报错信息 使用 Git 操作 版本库 , 删除分支时 , 报如下错误 : D:\Git\git-learning-course>git branch - ...

最新文章

  1. iOS环信聊天界面中点击头像和消息的几种状态
  2. 存储能否导致ESXi网络性能问题?
  3. 3142:[HNOI2013]数列 - BZOJ
  4. 基于kafka_2.11-2.1.0实现的生产者和消费者代码样例
  5. go语言基础到提高(3)-变量
  6. 一条数据的漫游 -- X-Engine SIGMOD Paper Introduction
  7. CF198D Cube Snake(三维空间/增量构造)
  8. 「日常训练」 Genghis Khan the Conqueror(HDU-4126)
  9. 解决Ubuntu系统终端运行python文件报错“ImportError/ModuleNotFoundError:No Module named xx”
  10. [Oracle]GoldenGate官方文档
  11. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_6 Mybatis中使用Dao实现类的执行过程分析-增删改方法...
  12. 2.7 if应用:猜拳游戏
  13. springcloud eureka集群_SpringCloud入门学习之Eureka
  14. GIT远程分支误删恢复
  15. 不可不知的CPU风扇清理技巧
  16. Python练习:四叶玫瑰数求解
  17. JS实现html页面点击下载文件的两种实现方法
  18. 卷积神经网络使用到的公式
  19. Python3初步实践教程概要
  20. 数组的length属性和String的length()方法

热门文章

  1. 学籍管理系统制作教程第一天
  2. 使用Intrinsics优化
  3. 3D游戏之父--John Carmack连载系列(四)
  4. git报 “The stash entry is kept in case you need it again“ 错误解析
  5. 关于网页抓取的10个误区(最新)
  6. 解决报错:OSError: Failed to open file b‘D:\\\xe5\xad\xa6\xe4\xb9\xa0\\scipy-_7cm39vc‘(图文并茂版详细版!!)
  7. 一觉醒后ChatGPT 被淘汰了
  8. 华为p9如何恢复手机删除的照片
  9. FITC-STL,PL;荧光素标记马铃薯凝集素(STL,PL)
  10. 极客日报:阿里回应1000万成立“元境生生”;马斯克一年上了75次热搜;微软.NET中文官网正式上线