故事背景
在git上创建了一个仓库(创建仓库时初始了一个README.md),需要将本地一个已存在目录指向这个git仓库,并将目录内容push到仓库
故事环境
1 | git --version |
开始探索
1 | git init |
遇到问题
1. 执行git pull origin master
1 | From github.com:xxxxx |
此时会提示拒绝merge
2. 执行git pull origin master --allow-unrelated-histories
1 | From github.com:xxxxxxx |
此时pull成功了,并将远程初始化的README.md拉到了本地
3. 执行git push origin master
此时可以正常push了,搞定
原因探究
Git refusing to merge unrelated histories -- StackOverflow
The default behavior has changed since git 2.9:
"git merge" used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. The command has been taught not to allow this by default, with an escape hatch --allow-unrelated-histories option to be used in a rare event that merges histories of two projects that started their lives independently.
See the git release changelog for more information.
You can use --allow-unrelated-histories to force the merge to happen.
后续补充
暂无