You could at least create an orphan branch in your new repo. (git checkout --orphan
), and make one dummy commit in it.
Or simply create a newbranch from Z
(still in your new repo)
This assume that you have your old repo cloned locally.
And that you have created a new repo, also locally.
cd c:\a\path
git init create newrepo
cd newrepo.
First, make sure your old repo is checked out at B (ie the SHA1 representing the commit before your branch)
cd C:\path\to\old\repo
git checkout B
Then import that content into your new empty repo
cd C:\a\path\newrepo
git --work-tree=C:\path\to\old\repo add .
git commit -m "Import old repo as Z"
You can fetch your old repo in that new repo, and rebase your commits on that new branch.
cd C:\a\path\newrepo
git remote add oldrepo C:\path\to\old\repo
git fetch oldrepo
git checkout -b newbranch
git rebase --onto newbranch C~ oldrepo/newbranch
That will recreate only the commits you want in your new repo.
But: the rebase can be problematic, and with many merge conflicts to be resolved manually.
In your case, you could avoid that entirely with git replace
or, in your case git graft points, as seen in this example.
Follow the past instructions up to the git fetch oldrepo
step, then:
git fetch oldrepo
git checkout -b newbranch oldrepo/newbranch
echo SHA1(C) SHA1(Z) > .git/info/grafts
(Replace SHA1(xxx)
by the SHA1 of the commit xxx
. Z
being the new commit done in the new repo, C
being the first commit of your newbranch
in the old repo)
That will declare Z
as parent commit of C
(no merge/rebase required here).
To make that permanent, use git filter-branch
:
git filter-branch --tag-name-filter cat -- newbranch
rm .git/info/grafts
You can then push that new rebased branch.
git remote add origin /url/of/new/remote/repo
git push -u origin master
git push -u origin newbranch