📢 📢 📢 📣 📣 📣
哈喽!大家好,我是「奇点」,江湖人称 singularity。刚工作几年,想和大家一同进步 🤝 🤝
一位上进心十足的【Java ToB端大厂领域博主】! 😜 😜 😜
喜欢java和python,平时比较懒,能用程序解决的坚决不手动解决 😜 😜 😜

✨ 如果有对【java】感兴趣的【小可爱】,欢迎关注我
❤️ ❤️ ❤️感谢各位大可爱小可爱! ❤️ ❤️ ❤️
————————————————
如果觉得本文对你有帮助,欢迎点赞,欢迎关注我,如果有补充欢迎评论交流,我将努力创作更多更好的文章。

今天想把之前python写的相关的文档操作的代码提交到码云进行托管,但是谁知道在init本地仓库的时候,没有注意目录,导致本地仓库创建错了,同时并提交了这个到远程仓库,等我在最外层重新创建仓库并进行提交到时候,发现报错了,具体的报错如下:

虽然只是一个简单问题,这里对于像我一样不熟悉git的小白来说,记录一下,方便大家。

git push origin master -f

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /Users/ligang/PycharmProjects/pdfProject/.git/
(venv) ligang@ligangdeMacBook-Pro pdfProject % git add ./
warning: adding embedded git repository: excel
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> excel
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached excel
hint:
hint: See "git help submodule" for more information.

报错的意思是我之前已经到远程仓库提交过了,需要到一个新的仓库进行提交,由于我不想重新创建远程仓库 所以将本地错的仓库删除,之后使用强制覆盖的方法,实现了正确的提交

如果我们确定远程分支上那些提交都不需要了,那么直接git push origin master -f,强行让本地分支覆盖远程分支。。。这个简单的解决了我的方法,但是在开发过程中需要使用下面的方法

但是在开发过程中需要使用下面的方法

但是在开发过程中需要使用下面的方法

远程分支上存在本地分支中不存在的提交,往往是多人协作开发过程中遇到的问题,可以先fetch再merge,也就是pull,把远程分支上的提交合并到本地分支之后再push。

入如果pull有这个报错:

fatal: refusing to merge unrelated histories

  此项错误是由于本地仓库和远程有不同的开始点,也就是两个仓库没有共同的 commit 出现的无法提交。这里我们需要用到 --allow-unrelated-histories。也就是我们的 pull 命令改为下面这样的:

git pull origin master --allow-unrelated-histories

如果设置了默认分支,可以这样写:

git pull --allow-unrelated-histories

今天的分享就到这里,

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐