两个分支拉出请求的等级完全不同的提交历史 [英] Two branches pull request yeilds entirely different commit histories
问题描述
我将一个存储库克隆到了我的计算机上:
I cloned a repo to my computer:
git clone <repo>
然后我在Github上创建了一个新的仓库.
Then I created a new repo on Github.
在我的克隆存储库中,我分配了一个远程源:
In my cloned repo I assigned a remote origin:
git remote <new repo>
我有两个分支: main
(在Github上标记为默认")和 master
.
I got two branches: main
(marked as 'default' on Github) and master
.
我开始与 master
一起工作.一切都很好,我什至可以推送"我的更改.但是当我尝试创建请求请求以将 master
合并到 main
中时.
I started working with master
. Everything was fine, I could even 'push' my changes. But when I tried to create a pull request to merge master
into main
.
我没有收到PR按钮,并收到通知
I didn't get a PR button and got the notification that
没有什么可比较的.
There isn’t anything to compare.
main和master是完全不同的提交历史.
main and master are entirely different commit histories.
我试图找到一种解决方案,但是由于缺乏对Git的经验,我无法确定其中一个是否适合我的问题.这里有很多[示例] [1].
I tried to find a solution, but because of my lack of experience with Git I can't decide if one of them fits in to my problem. Here are many [examples][1].
如何将我从 master
所做的更改合并到 main
中?
How can I merge my changes from master
into main
?
推荐答案
如果您收到有关新创建的Github存储库的错误,则可能是在以下情况下将文件添加到了默认的 main
分支中项目创建,例如 README.md
.
If you're receiving this error for a newly created Github repo, it's likely that you added files to your default main
branch during project creation, for example a README.md
.
您的本地 master
分支确实与远程 main
分支没有共享历史记录,并且您无法创建从一个请求到另一个请求的拉取请求.
Your local master
branch will indeed have no shared history with your remote main
branch, and you cannot create pull requests from one to the other.
要解决此问题,您需要检查本地获取 main
分支,然后在其顶部重新构建 master
分支,以便它共享 main
的历史记录:
To fix this, you need to check fetch your main
branch locally and then rebase your master
branch on top of it, so that it shares main
's history:
git fetch
git checkout master
git rebase origin/main
这篇关于两个分支拉出请求的等级完全不同的提交历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!