git常见错误记录(Your local changes to the following files would be overwritten by merge)

飘逸的风3年前 (2022-08-29)经验549

不常git不是一个好习惯。一旦git就会发现一堆错误,当着急分享代码给小伙伴的时候,这就情况不妙了,所以贴一些我遇到的错误。

当利用git bash向已存在的库中上传新代码时

执行 git push origin master报错:
To http://git.XXX.com/XXX/xxx
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://git.XXX.com/XXX/xxx'
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

提示得很清楚,远程代码库和本地代码库不一致,应该先把远程代码库本地化,即先执行git pull 。

所以接下来我们执行 git pull --rebase origin master

又报错:

error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

可以看出:如果有未提交的更改,不能git pull

只需

$ git stash
Saved working directory and index state WIP on master: 007c150 first commit

这时我们就可以拉取远程代码库的代码到本地了

$ git pull --rebase origin master

拉取完成

再执行

git stash pop


git stash #可用来暂存当前正在进行的工作
git stash pop #从Git栈中读取最近一次保存的内容

————————————————————————————————————————————————————————————————————

现在可以上传本地代码了!!!

执行git push origin master?

no no no !!! 这样会报错:

$ git push origin master
Everything up-to-date

这是因为没有在本地commit呀

那么

git add .

git commit -m 'update'

可以通过命令git status来查看是否还有文件未提交

 

最后git push origin master就可以了。


文章来源:https://www.cnblogs.com/AbsolutelyPerfect/p/8320286.html

相关文章

Git中解除项目中已经忽略的文件及文件夹

重新添加已经被忽略过的文件时,我们仅仅使用git add是不行的,因为git仓库中根本没有那个文件,这时候我们需要加上-f参数来强制添加到仓库中,然后在提交。比如上面设置了忽略排除的文件min.vue...

Linux 配置gitee

Linux 配置gitee

安装好git后, 如何配置连接至gitee ?首先, 需要在官网注册一个gitee账号, 然后进行以下配置步骤:1. 设置账号$ git config --global user.name &q...

Git 常用命令记录

代码推送到远端仓库初始化一个仓库mkdir test_git/  && cd test_git/初始化gitgit init添加代码touch index.phpgit ad...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。