Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Edit: It occurs to me that you could do this just with <code>git merge --no-commit</code>. This will attempt the merge, and even if it does not conflict, it will stop just before committing. At this point you can remove all the junk you don't need (including restoring conflicted files if necessary) and create a merge commit only containing the desired subtree.</p> <p>Original answer:</p> <p>You can indeed use filter-branch for this. An outline:</p> <p>Clone your source repo:</p> <pre><code>git clone --bare /path/to/bar /path/to/bar_clone </code></pre> <p>Using a bare clone will save you the time and space of creating a working directory.</p> <p>Next, use filter-branch on the clone:</p> <pre><code>git filter-branch --index-filter 'git rm -rf &lt;unwanted files/directories&gt;' -- --all </code></pre> <p>The <code>--all</code> lets it know that you want to use all refs, not just the current HEAD. You will now have a repository containing only the desired subdirectory, and all of the history associated with it.</p> <p>Note: Sorry, I don't know a really straightforward way to remove all but what you want. You have to be careful with wildcards because you don't want to clobber any git directories. Here's something that'll work, though it's slower, especially if you've got a lot of files:</p> <pre><code>git filter-branch --index-filter 'git rm -f `git ls-files | grep -v ^www/tools`' -- --all </code></pre> <p>Anyway, however you manage the listing of files to remove, you can go ahead with your subtree merge, pulling from <code>bar_clone</code> into <code>foo</code>.</p>
 

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