I've accumulated a lot of git commits for my project. As the first step in cleaning the repo up, I'd like to split every commit into two commits: one which only touches a particular file /some/directory/file, and another which touches everything else.
Since the git history is fairly long, I'd like to avoid doing this manually.
Some approaches that I've thought about (but haven't actually tried out) are:
git rebase --exec
with a script that does the splitting.filter-branch
. (don't have much familiarity with this tool)However, since this seems to me like a fairly common problem, I thought I would check here before attempting to reinvent the wheel. Is there any automated way to do this?
You are on the way, what you have tried is the way to do it.
As you found out you have 2 main options:
git rebase -i
aka: squash
(manual procedure)// Manipulate any commit by editing it and commitign again
git rebase -i HEAD~X
Since the git history is fairly long, I'd like to avoid doing this manually.
Read this article which address your problem How to tear apart a repository: the Git way
git filter-branch
will run on every commit specified in the condition and then you can do what ever you wish with it (via script) and not manually.
Here is another very useful article about filter-branch
Splitting a subfolder out into a new repository
// Remove any given file from commits
// Now you can commit it again into a new commit
git filter-branch --tree-filter 'rm -f <file name> HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With