1

I've been following the instructions on this answer from "Detach subdirectory into separate Git repository" on how to use the git subtree command in order to split a subdirectory out of a git repository. It worked on the first subdirectory, but my second directory gets split with missing commits.

My directory tree looks like this:

GitBooks
|
------ SQLBasics
|
------ RubyProgramming

I want to split both of these into their own separate repositories, and I have already done so on SQL-Basics. However, on RubyProgramming whenever I follow the exact same instructions from the above answer, the subdirectory gets split and is missing a bunch of commits. I'm pretty sure the reason is because I changed the directory name from Ruby Programming to RubyProgramming (notice the space in between) at one point in time, and I guess it's only carrying over the commits from RubyProgramming (no space).

My question is how do I carry over ALL of the commits from this subdirectory, even though I changed its name at one point in time. Is it possible to do this?

Thank you in advance.

Community
  • 1
  • 1
Hunter
  • 646
  • 1
  • 6
  • 23

1 Answers1

0

You could do something like this:

git filter-branch -f --prune-empty --tree-filter '[ -d RubyProgramming ] && mv RubyProgramming Ruby\ Programming' -- --all
git filter-branch -f --prune-empty --subdirectory-filter Ruby\ Programming --all

First undo the rename in your history and then extract the single directory.

michas
  • 25,361
  • 15
  • 76
  • 121
  • When inputing the first command, I get the output: `Rewrite 63feedc50f75677988c8365c2d65faaebe62cf47 (1/111)mv: rename RubyProgramming to Ruby Programming: No such file or directory tree filter failed: mv RubyProgramming Ruby\ Programming` – Hunter Jan 03 '15 at 05:50
  • Please *always* try to understand a command before blindly running it. (Otherwise some joker will suggest something like `rm -rf /`...) This is especially important with `git filter-branch` as it can really destroy your repository when used the wrong way. The first command takes each commit of the repository and trys to rename that directory. This of course fails if the directory is already renamed. I added a suitable test to the answer, but depending on your actual repository you might stumble into other problems as well. – michas Jan 03 '15 at 09:31