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 .git
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.
- Various other things that will not work.
- Clone the original repository.
- Create and switch to a new branch.
- Reset it to the commit
A
usinggit reset --hard COMMIT_HASH_A
. - Create a patch from
N <- O <- P
usinggit 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 git-rebase
help?