简体   繁体   English

合并缺少提交历史记录的git存储库到保留历史记录的存储库

[英]Merge a git repository lacking commits history to a repository that preserved history

I downloaded the source code of a C++ project instead of cloning its git repository at git://www.calatk.org/calatk.git 下载了C ++项目的源代码,而不是在git://www.calatk.org/calatk.git克隆其git存储库

Using this source code (with no git history), I created a git repo, worked on the code for a while, and pushed all my work/branches to my github at https://github.com/agirault/CalaTK 使用此源代码(没有git历史记录),我创建了一个git repo,处理了一段时间,然后将所有工作/分支推送到https://github.com/agirault/CalaTK上的 github。

I would now like to make a pull request to merge my code to the original git repository on calatk.git. 我现在想发出拉取请求,以将我的代码合并到 calatk.git上的原始git存储库中。

I was wondering how I could do this since I don't have the track from the previous commits in my repository. 我想知道如何才能做到这一点,因为我的存储库中没有以前提交的内容。 This repository on calatk.org should not have been updated since then, which means their last commit would be the same as my first commit available on my github. 从那以后就不应该更新calatk.org上的此存储库,这意味着它们的最后一次提交将与我在github上可用的第一次提交相同。

Assuming you don't mind replacing your published GitHub repository with one that contains the original project's history†, here is what I would try: 假设您不介意将发布的GitHub存储库替换为包含原始项目的历史记录†的存储库,请尝试以下操作:

  1. Add the upstream repository as a second remote: 将上游存储库添加为第二个远程数据库:

     git remote add upstream <clone-url> 
  2. Fetch from upstream: 从上游获取:

     git fetch upstream 

    This should generate new branch pointers including upstream/master . 这将生成新的分支指针,包括upstream/master upstream/master should not share history with your existing commits. upstream/master不应与您现有的提交共享历史记录。 That is, you'll have two root commits: one from the upstream project and one from your fork. 也就是说,您将有两个root提交:一个来自上游项目,另一个来自您的fork。

  3. Rebase your work onto the upstream commits (assuming we only have master to worry about): 将您的工作基于上游提交(假设我们只需要担心master ):

     git checkout master git rebase upstream/master 

    At this point you should only have one root commit: the one from the upstream project. 此时,您应该只有一个根提交:上游项目中的一个。 The hash for your old root commit, which should now no longer be a root commit, should match what is shown in the upstream project ( 3cee904 ). 您原来的根提交的哈希(现在不再是根提交)应与上游项目中显示的哈希匹配( 3cee904 )。

    You can use something like git show 3cee904 to make sure that the commit is correct. 您可以使用git show 3cee904来确保提交正确。

  4. Force push your new history to GitHub: 强制将您的新历史记录推送到GitHub:

     git push --force origin master 
  5. Submit your changes to the upstream repository according to their contribution guidelines. 根据他们的贡献准则将更改提交到上游存储库。

    Since it's not on GitHub or BitBucket it's not likely that they'll be able to accept a pull request (that's a proprietary feature). 由于它不在GitHub或BitBucket上,因此他们不太可能接受拉取请求(这是专有功能)。 You should be able to request push access or use git format-patch , though. 不过,您应该可以请求推送访问或使用git format-patch The upstream maintainers could also fetch from your public GitHub repository. 上游维护者也可以从您的公共GitHub存储库中fetch

Important note: If you've got collaborators on your GitHub project this may not be the best option. 重要说明:如果您在GitHub项目上有合作者,这可能不是最佳选择。 Modifying shared commits in Git is generally discouraged. 通常不建议在Git中修改共享提交。 I'm only recommending it since it sounds like your GitHub repository is effectively a personal repository. 我只推荐它,因为听起来您的GitHub存储库实际上是一个个人存储库。

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

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