简体   繁体   English

来自不同存储库的拉取请求

[英]Pull request from a different repository

I didn't know how forks and clones work.我不知道分叉和克隆是如何工作的。 So in order to copy someone else's repo and work on it, I downloaded the repo's files (using no source control), created my own new repository, and then committed those files to it.因此,为了复制别人的存储库并对其进行处理,我下载了存储库的文件(不使用源代码控制),创建了我自己的新存储库,然后将这些文件提交给它。

I want to pull request my repo's master to the original repo, but I can't because it's not a fork.我想请求我的回购协议的主人到原始回购协议,但我不能,因为它不是叉子。 Furthermore - git doesn't even know that they originate from the same source, and hence if I checkout the original repo, open a new fork, copy-paste all the files from my private repo to the new fork, and pull request it back in, it will show it as a single giant commit, and I'll lose all of the commit and comment history on the old repo, which will be terrible.此外 - git 甚至不知道它们来自同一来源,因此如果我检查原始回购,打开一个新的分叉,将所有文件从我的私人回购复制粘贴到新的分叉,然后拉回请求in,它将显示为单个巨大的提交,我将丢失旧回购协议中的所有提交和评论历史,这将是可怕的。

Is there a way for me to pull request my changes back into the original repo without losing all the history of my copied repo?有没有办法在不丢失我复制的回购的所有历史记录的情况下,将我的更改请求拉回原始回购?

  1. Make sure you have a copy of your changes on your local computer (I'll call this "the copied repo") and delete the project on GitHub, if you've created one.确保您在本地计算机上有一份更改的副本(我将其称为“复制的存储库”)并删除 GitHub 上的项目(如果您已经创建了该项目)。
  2. Click "Fork" on the upstream project's GitHub page.在上游项目的 GitHub 页面上单击“Fork”。
  3. After the forking process is complete, clone that repository to your local computer (I'll call this "the forked repo").在分叉过程完成后,将该存储库克隆到您的本地计算机(我将其称为“分叉存储库”)。
  4. Copy all changed files from the copied repo into the forked repo.将所有更改的文件从复制的存储库复制到分叉存储库中。
  5. Verify that it's working as you expect, then look at the changes using git status and git diff and commit them.验证它是否按预期工作,然后使用git statusgit diff查看更改并提交它们。
  6. Push those changes back to GitHub.将这些更改推送回 GitHub。
  7. In a moment, a banner should appear on the cloned repo's GitHub page that provides a button to open a pull request back to the upstream repo.稍后,克隆存储库的 GitHub 页面上应该会出现一个横幅,其中提供了一个按钮来打开一个返回上游存储库的拉取请求。 Click that and open the pull.单击它并打开拉。

unfortunately there is no way to merge two branches that dont have a common ancestor commit.不幸的是,没有办法合并两个没有共同祖先提交的分支。 even if the files are the same.即使文件相同。

A very hacky workaround however goes as follows:然而,一个非常hacky的解决方法如下:

  1. fork and clone the original repo fork 并克隆原始 repo
  2. in that repo, checkout to the commit that you initially downloaded.在该存储库中,签出您最初下载的提交。
  3. in your non-forked, downloaded repo, checkout to the first commit you made after having downloaded it.在你的非分叉的、下载的 repo 中,签出你下载后所做的第一次提交。
  4. copy those files into the forked repo将这些文件复制到分叉仓库中
  5. Recreate the commit in the forked repo在分叉仓库中重新创建提交
  6. repeat steps 3-5, but for each successive commit.重复步骤 3-5,但对于每个连续的提交。
  7. Once completed, you can open up a pull request with you newly created git history完成后,您可以使用新创建的 git 历史打开拉取请求

Its a laborious process, and you could probably create a tool to do it, but if its not a lot of commits, or you dont mind combining a few commits into one.这是一个费力的过程,您可能可以创建一个工具来完成它,但是如果提交不是很多,或者您不介意将几个提交合并为一个。 (to do this, in step 3, just skip a couple of commits, the code from previous commits will still be there) (要做到这一点,在第 3 步中,只需跳过几次提交,之前提交的代码仍然存在)

You need first to connect the old repository OLD (containing proper git history) to the new one NEW (disconnected but containing modifications) by:您首先需要通过以下方式将旧存储库 OLD(包含正确的 git 历史记录)连接到新存储库(断开连接但包含修改):

  1. from NEW, revert to the first commit : git checkout $(git rev-list --max-parents=0 HEAD | tail -n 1)从新的开始, 恢复到第一次提交git checkout $(git rev-list --max-parents=0 HEAD | tail -n 1)
  2. synchronize OLD with this state: rsync -avrI. /path/to/NEW将 OLD 与此 state 同步: rsync -avrI. /path/to/NEW rsync -avrI. /path/to/NEW
  3. create a patch with commits from NEW latest commit to second commit: git checkout main && git format-patch -1 $(git rev-list --max-parents=0 HEAD | sed 'x;$!d')创建一个补丁,其中包含从新的最新提交到第二次提交的提交: git checkout main && git format-patch -1 $(git rev-list --max-parents=0 HEAD | sed 'x;$!d')
  4. from OLD, apply the create patch: git am <../path/to/patch.从 OLD,应用创建补丁:git am <../path/to/patch。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM