Question

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>
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top