如何将从performce克隆的本地repo合并到现有的GitHub repo中



我在GitHub上有一个私人回购。我的电脑上有它的本地工作区。

我在Perforce中有一些depo流,我用"git p4 clone"将其克隆到计算机上的本地repo工作区中。原因是为了保留Perforce的历史。

现在我想把我从Perforce克隆的本地回购推送到GitHub上现有的私有回购中(我在开头提到的那个(。

有人能带我走台阶吗?

到目前为止,我尝试过:

git p4 clone "my-perforce-stream-path"

然后我尝试了:

git remote add origin "my-private-github-repo-url"
git push -u origin master

我得到一个错误:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'my-private-github-repo-url'

您首先需要从performce repo拉入私有github存储库。一旦你做到了这一点,并且github repo与performe repo同步,你就可以将你的主分支推送到github repo。按照下面两个备选方案中的一个来完成这项工作:

备选方案1

  1. 创建github repo:的本地副本

    git clone your-github-repo.git

  2. 添加远程:

    git remote add p4 "perforce-repo-path"

  3. 将更改从p4远程设备拉入本地:

    git pull p4 branch-name

    3.1.注意:如果repo、github和performce都不相关(意味着它们包含彼此不相关的历史记录(,您可能会出现错误,因为git不允许您将一个分支从不相关的repo合并到另一个分支。您可以使用--allow-unrelated-histories选项来覆盖它,如下所示:

    git pull p4 branch-name --allow-unrelated-histories

  4. 最后,您应该能够将您的本地更改推送到github:

    git push -u origin master

备选方案2

  1. 在性能存储中添加github远程:

    git add remote github url.git

  2. 接下来,确保将github远程分支的历史记录拉入本地性能存储库(在推送之前同步(:

    git pull github <branch-name> --allow-unrelated-histories(如果两个转发都包含不相关的更改/历史记录,--allow-unrelated-histories有助于防止收到错误(

  3. 然后,将您在性能回购中的分支推送到github远程:

    git push -u github <branch-name>

    注意:如果您对历史记录有任何问题,可以在此处使用相同的--allow-unrelated-histories标志。

最新更新