replay git commits on repo with different root
Asked Answered
S

2

6

I am one of the current maintainers of the FreeGLUT project on sourceforge. This code is stored in an SVN repo, but to stimulate contributions of others, I want to make a git repo available. I already have a git-svn clone of the svn trunk up on github currently at github (made through SmartGit, which is not really compatible with git-svn actually).

I made this by cloning https://svn.code.sf.net/p/freeglut/code/trunk/freeglut. However, I now find that I should have cloned https://svn.code.sf.net/p/freeglut/code and have SmartGit's svn bridge figure out the branches and trunk.

I have made this new correct clone locally. Now the problem: I already have a few commits in my local git repo of the old/wrong clone. I would like to transfer these over to my new repo, but as the root directories on disk are not the same, a simple rebase strategy as outlined here would not work (I think).

I could do it with patches, as git apply has the --directory argument to prefix the paths in the patch files that would make things work, but then I would have to do it commit by commit. At least, I have not found a way to put multiple commits in a single patch file (without squashing) and replay them all on top of my HEAD.

How to I best solve my problem?

Sukkoth answered 2/1, 2014 at 16:2 Comment(3)
possible duplicate of Applying commits from one subtree to another in same repoPathetic
@jthill, you are right, that does appear to be a duplicate. I didn't consider those search terms...Sukkoth
Why would it be, it's not about the SAME repo but a different one.Fratricide
S
10

Ok, it turns out that:

  1. git format-patch can generate a file containing a range of commits, such as a whole branch.
  2. git am with the --directory option can replay the commits contained in the patch file one by one (see here) and commit them for me.

Problem solved!

Sukkoth answered 3/1, 2014 at 1:54 Comment(2)
nice answer.I didn't think this question this way.Vitellin
The secret sauce to git format-patch seems to be the --root flag (How to use git format-patch on initial commit). However, another option is to git remote add other [email protected]:user/repo.git && git fetch other && git merge --allow-unrelated-histories --no-ff other/master -m "Merge history from other".Wirework
V
0

Yes,you could do it with patches.

  1. Reset last commit by using git reset --soft 'HEAD^'. or if you have 3 commits. just do git reset --soft HEAD~3
  2. Do patches.

I think this answer explain it well.

Vitellin answered 2/1, 2014 at 16:14 Comment(1)
thanks for the help! However, I don't see why i would want to reset head and then do patches, I have a clean head and only patches to apply.Sukkoth

© 2022 - 2024 — McMap. All rights reserved.