views:

27

answers:

1

For my school projects, I was used to have one big repo with several subdirectories for the specific projects. Because I had no time, I always commited anything into the master branch.

The problem is, that this turns out to be unpracticable, as it becomes more and more difficult to revert older commits or figuring out which commit belongs to what whithout reading the message.

Currently it looks like this:

Dir-tree:

projects/
  projectA/
  projectB/
  projectC/
  ...

Repo:

A---B---C---D---E---F---G<master>

I found out, that almost all commit (apart from about five, which I can fix by hand) just modify files in one of these folders.

Is there an easy (automatred?) way (script?) which does the painfully work of automatically assigning the commits to the projects and creating different branches? I want to have something like this at the end:

Repo:

A---C---G<project A>
|\
| \
|  \
|   B---D<project B>
E---F<project C>
+1  A: 

You're looking for git filter-branch using the --subdirectory-filter option.

Creating three branches for the three projects you want, and then running git filter-branch --subdirectory-filter projectX in those branches should give you the desired result.

You might also want to consider just using a repository per project. Once you've done the above, making new repositories, each containing one of the branches you created earlier as its master, will be trivial.

rafl
Can please you explain an unexperienced user how to do the splitting into different repos detailed?
FUZxxl
For a more elaborate answer, feel free to ask a new question, but the basic idea is to just create, say, 3 new repositories using `git init`, fetching all the objects from the repository containing the the branches for each directory, and then setting the master of each of the new repositories to whatever was in the corresponding branch. After that you can delete the other branches in the per-project repositories and possibly also instruct git to delete all the objects referencing commits to other projects, which are now unaccessible from the new repo's master anymore.
rafl