1' OR 1 -- 1' OR 1 -- - 5 months ago 27
Git Question

Reapply Git commits from copied fork repository to original repository

A university colleague of mine thought it was a good idea to fork a repository by cloning it and copy its contents into a new, freshly initialized repository but without the

folder from the original repository. Afterwards, he simply committed this copy using a single commit and the whole team began working on the project based on this commit:

A <- B <- C <- D <- E (original repository)
\ clone / |_____|
\ / |
\ / Ofc. work on the original repository was continued after cloning...
\ /
M <- N <- O <-P (our "fork", commits from my team)

Now, my first goal is to get the following repository structure:

A <- B <- C <- N <- O <- P

What I have been trying to do now during the past few hours is the following:

    • Clone the original repository.

    • git diff > /path/to/patch
      from within the fork.

    • git apply
      within the original repository.

    • Works, but does not preserve the commits.

  1. Various other things that will not work.

    • Clone the original repository.

    • Create and switch to a new branch.

    • Reset it to the commit
      git reset --hard COMMIT_HASH_A

    • Create a patch from
      N <- O <- P
      git format-patch COMMIT_HASH_M --stdout > /path/to/patch
      on the fork.

    • Apply this patch on the original repository using
      git am -3 /path/to/patch
      . After resolving several conflicts such as the duplicate creation of empty files, this will result in the following error:
      fatal: sha1 information is lacking or useless (some_file_name).
      Repository lacks necessary blobs to fall back on 3-way merge.
      This is where I cannot get on.

So how do I create a repository including all commits from the original repository and from our team as described, so that eventually, a pull request could be sent to the original repository? Might a


If you don't insist on linear history, you can merge your fork into original repository.

In the original repo drirectory:

git remote add fork /path/to/fork
git fetch fork
git merge fork/master

This will preserve commits and may result in liner history (no merge commit) if the merge can be fast-forwarded.