Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to move a subdirectory from a branch in one git repository to a branch in a different repository, preserving history?
    primarykey
    data
    text
    <p>I've got a directory containing utility libraries that were developed in a branch in one git repository, but it turns out they really belong in a different directory in a different project. I've read through and attempted Greg Bayer's <a href="http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/" rel="nofollow">Moving Files from one Git Repository to Another, Preserving History</a> multiple times, but I'm unable to preserve history. I'm attempting to do this all under non-master branches to be more safe as the project is not ready to merge back to master yet anyway.</p> <p>Here's what I'm doing so far:</p> <p><em>Preparing the "DirectoryName" directory to be moved from branch "SomeBranch" of "Repo1" repository:</em></p> <pre><code>cd ~/Desktop git clone git@github.com:username/Repo1.git cd Repo1 git checkout -b SomeBranch origin/SomeBranch git remote rm origin git filter-branch --subdirectory-filter DirectoryName mkdir DirectoryName git mv *.php *.txt DirectoryName git add DirectoryName git commit -m "Stripped everything down to just DirectoryName." </code></pre> <p><em>Merging the "DirectoryName" directory into the "SomeBranch" branch of the "Repo2" repository:</em></p> <pre><code>cd ~/Desktop git clone git@github.com:username/Repo2.git cd Repo2 git checkout -b SomeBranch origin/SomeBranch git remote rm origin git remote add Repo1 ../Repo1/ git pull Repo1 SomeBranch git remote rm Repo1 </code></pre> <p>When I do this I can successfully strip everything down to "DirectoryName" in Repo1 (and I can pull it over to Repo2 as well), but the history is lost. If I do a <code>git log -- DirectoryName</code> or <code>git log -- DirectoryName/SomeFile.php</code>, I only see the "Stripped everything down to just DirectoryName." commit). So, clearly something is wrong with my <code>git filter-branch</code> command, but I'm not familiar enough with it to figure out what.</p> <p>Any suggestions would be greatly appreciated as we're undergoing some fundamental changes to our codebase, so I'll need to be doing this relatively frequently for a while as stuff moves around (but we want to preserve the history).</p> <p><strong>Update:</strong> As I mentioned <code>git log -- DirectoryName</code> (or <code>git log -- DirectoryName/SomeFile.php</code>; either in Repo1 or Repo2) does not show any commits other that the "Stripped everything down to just DirectoryName." commit, but if I do <code>git log</code> I see the correct commit history. Am I just using <code>git log</code> incorrectly or is there some corruption that's causing the commits to not show up correctly?</p> <p><strong>Another Update:</strong> <code>git log -- DirectoryName</code> <em>does</em> show the correct commits in my original, unmodified Repo1, but it <em>does not</em> show the correct commits after the <code>git filter-branch</code> (and I've tried <code>git filter-branch --subdirectory-filter DirectoryName -- --all</code> but that mucks with the "master" branch as well and doesn't appear to be necessary... same result). That said, the commit history is there after running <code>git filter-branch</code>, I can see it all with <code>git log master..</code> it just no longer seems to pertain to the directory or the files. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload