git - Merge from upstream with no upstream history -


i have parent repo containing project, , sub repo based off project.

the parent repo has tagged releases, , sub repo based off 1 of these tags. example:

parent v1.0---v2.0---v3.0                 \                  child---[changes] 

unfortunately when child repo created, parent history removed , repo reinitialised files added scratch. means none of parent repo's history contained within child repo, rather, 1 commit @ start indicate based off parent's v2.0 tag of v2.0 files git added.

is there way use git merge upstream changes parent (eg. v3.0 tag) child despite there being no parent history?

git pull tells me there no common commits, doesn't know start merging guess. need rewrite history of child add parent's history back?

obviously weird scenario , not 1 allow in future :)

then suggest rewrite history of child repo have full history v2.0 backwards.

i assume branch called master in both repos.

so first add remote parent repo , fetch it

$ cd /path/to/child/repo $ git remote add origin <url_or_path_for_parent_repo> $ git fetch origin 

then find out sha of v2.0 tag (the 1 full history):

$ git rev-parse v2.0 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 

and sha of first commit in master branch, i.e. 1 entire v2.0 history squashed 1 commit:

$ git checkout master $ git log --reverse --format=format:%h | head -n 1 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 

then, rewrite master branch swap parent bbbbb.. aaaaa... (please replace bbbbb... , aaaaa... strings in command below actual results of commands run above)

$ git filter-branch --parent-filter 'read p ; if [ "$p" = "-p bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ]; echo "-p aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ; else echo "$p" ; fi' rewrite cccccccccccccccccccccccccccccccccccccccc (d/d) ref 'refs/heads/master' rewritten 

after master branch should have replaced first squashed commit history of v2.0 tag.

if went wrong, can revert master branch original state with:

$ git reset --hard original/refs/heads/master 

after have verified results , happy, can rid of original/refs/heads/master backup branch by:

$ git update-ref -d refs/original/refs/heads/master 

after able merge v3.0 tag master branch of child repo in normal fashion.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -