On Fri, 22 May 2015 04:04:43 -0700 (PDT) Kalpa Welivitigoda <callka...@gmail.com> wrote:
> My question is basically moving a directory from one git repo to > another with the commit history for that directory. Let me elaborate > more. > > Say we have two git repositories repoA and repoB with the following > directory structure > > repoA > --dir1 > -- dir1-1 > -- dir1-3 > --dir2 > > repoB > --dir1-2 > > I need to move the dir1-2 from repoB to repoA so that the directory > structure of repoA will look like the following, > > repoA > --dir1 > -- dir1-1 > -- dir1-2 > -- dir1-3 > --dir2 > > In doing so, I need to preserve the commit history for dir1-2 as well. > > How can I achieve this? Are there any other alternative ways that I > can achieve a similar outcome? Use the `git subtree` command [*]. First, use `git subtree split` to produce a synthetic chain of commits which only touched the directory you need the history of, then fetch that history into the destination repository and merge it there. For this, you can either use `git subtree add` or direct subtree merging [1]. Note that the commits in the chain `git subtree split` produces are synthetic (i.e. created by `git subtree split`), and their SHA-1 names do not match to those in the original repository's history. [*] This command should now be available as part of Git. If your Git install does not expose it directly, look for it in the "contrib" section of your Git install and run it there -- it's just a POSIX shell script. 1. https://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.