当前位置: 首页 > news >正文

Git使用的一些问题

问题1:hint: Updates were rejected because the tip of your current branch is behind

使用git提交本地仓库信息至远程仓库时出现以下报错:
在这里插入图片描述
首先看下 这个问题出现的原因:
在GitLab后台创建一个新的远程项目,勾选了“使用自述文件初始化仓库”,如图所示:
在这里插入图片描述
这样的话会在项目中自动创建一个README.md文件,在本地仓库的项目除非是通过Clone进行克隆远程仓库的项目,不然在提交之前,需要使用git pull origin master命令将远程仓库的文件拉去下来,在本地进行合并,再进行push提交。

一般情况下以上的操作会直接成功,但是在实际操作的过程中,可能会出现以下报错:
在这里插入图片描述
出现这个问题的最主要原因还是在于本地仓库和远程仓库实际上是独立的两个仓库,远程仓库的文件和本地仓库的文件不一致,需要将远程和本地文件的进行合并达到一致,然后再进行push操作。假如之前是直接clone的方式在本地建立起远程github仓库的克隆本地仓库就不会有这问题了。

查阅了一下资料,发现可以在pull命令后紧接着使用--allow-unrelated-histories选项来解决问题(该选项可以合并两个独立启动仓库的历史)。
在这里插入图片描述
然后再push提交即可:
在这里插入图片描述

问题二:使用push命令时出现:Failed with error: unable to access ‘https://github.com/firstPro.git/’: The requested URL returned erro 403

使用命令git push --set-upstream origin master提交远程仓库代码时,出现报错如下:
Failed with error: unable to access ‘https://github.com/firstPro.git/’: The requested URL returned erro 403

解决:因为本地计算机绑定了默认的github账号,这里需要将绑定的账号删除
在这里插入图片描述

然后再使用git push命令即可.

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (master)
$ git push --set-upstream origin master
Logon failed, use ctrl+c to cancel basic credential prompt.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 209 bytes | 52.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/982837387/firstPro/pull/new/master
remote:
To https://github.com/982837387/firstPro.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

在本地创建的分支,也可以通过push的方式在远程创建一个相同的分支,比如创建一个v1分支:

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (master)
$ git branch
* master

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (master)
$ git branch v1

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (master)
$ git branch
* master
  v1

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (master)
$ git checkout v1
Switched to branch 'v1'

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git branch
  master
* v1

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git status
On branch v1
nothing to commit, working tree clean

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git log
commit f41fef2d74830d873c482d1a43d0bb2bc1e63a0e (HEAD -> v1, origin/master, master)
Author: wshy0924 <wshy0924@126.com>
Date:   Mon Dec 14 13:57:50 2020 +0800

    create test.html

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git status
On branch v1
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.html

no changes added to commit (use "git add" and/or "git commit -a")

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git add .

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git commit -m 'v1 change info'
[v1 c2e6871] vv1 change info
 1 file changed, 1 insertion(+)

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git status
On branch v1
nothing to commit, working tree clean

ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git push
fatal: The current branch v1 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin v1


ASUS@LAPTOP-999H49BF MINGW64 ~/Desktop/firstPro (v1)
$ git push --set-upstream origin v1
Logon failed, use ctrl+c to cancel basic credential prompt.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 264 bytes | 264.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'v1' on GitHub by visiting:
remote:      https://github.com/982837387/firstPro/pull/new/v1
remote:
To https://github.com/982837387/firstPro.git
 * [new branch]      v1 -> v1
Branch 'v1' set up to track remote branch 'v1' from 'origin'.

在这里插入图片描述

问题三:git push 提交时,Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’

解决办法:通过git remote rm origin 移除绑定的远程仓库地址
再使用git remote add origin url 添加远程仓库地址

如果这样仍然不能解决的话,可以通过新建一个分支,然后利用这个分支进行push,然后再合并,或者需要将本地分支切换到与远程分支一样的分支进行提交,比如原本是在develop分支里面提交的push到远程仓库的master,可以先在本地切换到master,然后再进行 git push -u origin master操作。

问题四:Logon failed, use ctrl+c to cancel basic credential prompt. remote: Invalid username or password

首先解释下这个问题出现的场景吗,在Git Bash中使用git push 提交代码时,首次提交GitHub时会提示登录GitHub账号,分两次登录:
第一次:GitHub登录的用户名和密码
第二次:GitHub的用户名和生成的token密码
这里由于没有设置第二次登录的用户名和密码,所以才会出现这个报错。解决方案如下所示:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

问题五:Another git process seems to be running in this repository, e.g.

详细报错信息:

$ git add .
fatal: Unable to create 'E:/work/FHR发布/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

这段报错意思是,在另外一一个仓库中也存在另一个进程使用这个仓库,在./git/index.lock已经存在。
解决:需要在./git文件夹中将index.lock删除即可,也可以使用命令删除:rm .git/index.lock
在这里插入图片描述

相关文章:

  • sql中单字段模糊查询多个匹配字段
  • 循环遍历List中for循环与foreach区别与使用
  • GitHub Page个人博客中评论功能
  • 钉钉中一些api的使用
  • sql server中存储过程的使用
  • sql中报错:“从数据类型 varchar 转换为 bigint 时出错”解决
  • c#中Excel转为DataTable对象
  • SQL Server Always Encrypted加密使用
  • .Net中wcf服务生成及调用
  • sql中视图的使用
  • VB中Http请求测试
  • springboot集成SqlServer的坑
  • HttpClient请求Https证书问题解决
  • springcloud中使用ribbon实现负载均衡报错问题
  • Spring基础
  • 【译】React性能工程(下) -- 深入研究React性能调试
  • Git 使用集
  • Iterator 和 for...of 循环
  • JavaScript 基本功--面试宝典
  • JavaScript的使用你知道几种?(上)
  • markdown编辑器简评
  • Transformer-XL: Unleashing the Potential of Attention Models
  • vue自定义指令实现v-tap插件
  • Windows Containers 大冒险: 容器网络
  • 从零开始的无人驾驶 1
  • 入口文件开始,分析Vue源码实现
  • 实战|智能家居行业移动应用性能分析
  • 手写双向链表LinkedList的几个常用功能
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 白色的风信子
  • FaaS 的简单实践
  • 第二十章:异步和文件I/O.(二十三)
  • 函数计算新功能-----支持C#函数
  • 专访Pony.ai 楼天城:自动驾驶已经走过了“从0到1”,“规模”是行业的分水岭| 自动驾驶这十年 ...
  • $ git push -u origin master 推送到远程库出错
  • $forceUpdate()函数
  • (1)Map集合 (2)异常机制 (3)File类 (4)I/O流
  • (4)通过调用hadoop的java api实现本地文件上传到hadoop文件系统上
  • (AngularJS)Angular 控制器之间通信初探
  • (C#)获取字符编码的类
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (Matlab)遗传算法优化的BP神经网络实现回归预测
  • (Ruby)Ubuntu12.04安装Rails环境
  • (保姆级教程)Mysql中索引、触发器、存储过程、存储函数的概念、作用,以及如何使用索引、存储过程,代码操作演示
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (每日持续更新)jdk api之StringBufferInputStream基础、应用、实战
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • (转)Scala的“=”符号简介
  • (转)编辑寄语:因为爱心,所以美丽
  • (转)负载均衡,回话保持,cookie
  • **CI中自动类加载的用法总结
  • .NET 4.0中使用内存映射文件实现进程通讯
  • .NET MAUI学习笔记——2.构建第一个程序_初级篇