使用git 的各种报错

使用git 的各种报错

在git 上创建了一个仓库(附带README文件),在上传本地文件的过程中出现的问题

1:git remote add 自定义远程仓库名字 (本次我的是my_summary)远程仓库的地址
2:git add .
3:git commit “注释”
4:git push -u 远程仓库名字 本地分支名字

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

此处报错是因为少了初始化:git init

  • 之后再执行以上命令到git push
报错:
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/fairy66/My_summary.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

此处的报错大概意思是“远程仓库中的一些东西,本地是没有的,所以提交被拒绝”,需要执行git pull

  • 接着执行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=my_summary/<branch> master
  • 大概意思是你当前分支没有指定跟踪信息,需要指定与哪个分支合并。根据最后一行提示进行操作
  • 解决:
git pull 远程仓库名字  本地分支名字

再执行

git branch --set-upstream-to=my_summary/<branch> master   
<branch> 指的是远程分支的名字  

**远程分支的信息也可以使用git branch -a或者git branch -r来查询,此处如下:

在这里插入图片描述
执行完这个命令,会提示关联成功,在这里插入图片描述

  • 再次执行git pull
 - 报错:fatal: refusing to merge unrelated histories

解决-执行以下命令:翻译过来就是循允许不相关的历史记录

git merge my_summary/master --allow-unrelated-histories

之后出现:
在这里插入图片描述
输入i:注释——ESC——:wq回车—— git push -u 远程仓库名字 本地分支名字

报错:
You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

错误可能是因为在你以前pull下来的代码没有自动合并导致的
解决方法:

1.保留你本地的修改

git merge --abort

git reset --merge

合并后记得一定要提交这个本地的合并

然后在获取线上仓库

git pull

2.down下线上代码版本,抛弃本地的修改

不建议这样做,但是如果你本地修改不大,或者自己有一份备份留存,可以直接用线上最新版本覆盖到本地

git fetch --all

git reset --hard origin/master

git fetch

3.合并代码

git stash

会把所有未提交的修改(包括暂存的和非暂存的)都保存起来,用于后续恢复当前工作目录。通过git stash命令推送一个新的储藏,当前的工作目录就干净了

git pull

拉取最新的代码

git stash pop

从git栈中获取到最近一次stash进去的内容,恢复工作区的内容。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值