Note that there are some explanatory texts on larger screens.

plurals
  1. POPull existing Git repo into subtree with full history (no squashing)
    primarykey
    data
    text
    <p>We currently use TFS in our organization but are looking into TFS 2013's built-in Git support. I'd like to pull an existing branch from TFS, with all of its history, into a differently named subfolder in Git (yes, I realize creating a separate Git repo for each would be better, but "for reasons" I can't do that just yet).</p> <p>So I used git-tfs to clone the TFS history into a new repo. None of the Git changes will ever be pushed back to TFS so no problem there.</p> <pre><code>git tfs init http://ExistingTfs:8080/tfs/DefaultCollection $/Path/To/Branch oldtfs git tfs fetch </code></pre> <p>I then cloned the new repo locally and added <strong>oldtfs</strong> as a remote.</p> <pre><code>git clone http://NewTfs:8080/tfs/DefaultCollection/_git/NewRepo newtfs git remote add oldtfs ../oldtfs </code></pre> <p>Next I first tried using a <a href="http://nuclearsquid.com/writings/subtree-merging-and-you/" rel="nofollow">subtree merge</a> to pull the commits from <strong>oldtfs</strong> into <strong>newtfs</strong> and committed locally.</p> <pre><code>git merge -s ours --no-commit oldtfs/master git read-tree --prefix=MyProject/MyDir/ -u oldtfs/master git commit -m 'import old TFS' </code></pre> <p>It seemed to work well ("git log" showed all the history in the right place) but when I pushed back up to TFS, it appeared as only a single merge commit, although it did have two parents as I'd expect.After a bit more reading, it sounded like a rebase is what I need.</p> <p>So I created two branches in <strong>newtfs</strong>, <strong>import</strong> and <strong>squash</strong>. I performed the subtree merge in <strong>import</strong> and then rebased into <strong>squash</strong>.</p> <pre><code>git checkout import [...subtree merge as above...] git rebase squash </code></pre> <p>The result of this, however, is that <strong>import</strong> now has all the original TFS commits in its root (not /MyProject/MyDir), and <strong>squash</strong> seems to be unaffected.</p> <p>Next, I tried using the new <a href="https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt" rel="nofollow">"git subtree" script from contrib</a> (in a fresh clone from the remote TFS)</p> <pre><code>git subtree add -P MyProject/MyDir </code></pre> <p>Again, looked great locally but pushing back up to the TFS server showed everything squashed into one subtree commit (but again with multiple parents).</p> <p>Lastly, I tried git subtree with rebasing into a second branch with common ancenstor. Same problem as before: my imported commits were no longer in the subdirectory.</p> <p>So is my understanding of rebase incorrect, or is it just that the subtree merge and subtree script aren't compatible with it?</p> <p>My next approach was going to be attempting <strong>filter-branch</strong> to rewrite the <strong>oldtfs</strong> before importing or rebasing (again, <strong>oldtfs</strong> will never be shared/uploaded after it serves its purpose of importing). Is that the best option here?</p> <p>(The reason I want to "get this right" is that I want to publish a repeatable recipe or script for others in the department to use in a similar manner).</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.
 

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