Reputation: 29987
I have a repository in which, at some point, a directory was added. Initially it looked like this directory would live with this repo but finally I decided to extract it into its own repo, independent of the first one.
I did this according to GitHub instructions. The extraction was a success, I was left with only the directory I needed.
When looking at the git history, I see that the part which is not relevant to that specific directory is still there:
The directory was initially added with the "added alerting module" commit (first one at the bottom of the yellow area):
Is it possible to get rid of the "gray" commits (ending up on the branch original/refs/heads/master
)?
This is not a critical need - I can live with that part being dragged forever (and not updated in this repo) but for mostly aesthetical reasons I would be glad to get rid of it.
Upvotes: 0
Views: 95
Reputation: 725
You can use git filter-branch just like you did it to get the result the other way round. Just replace subdirectory-filter
(which means "only keep specified directory") with index-filter
(which means "do something with the index before each commit").
To specify the "something" in "do something", index-filter takes as parameter a bash command which should modify the git index. In your case, the command should simply delete the unwanted directory. For example:
--index-filter 'git rm -r -q --cached --ignore-unmatch the/unwanted/directory'
Leave everything else just you had it when extracting the directory.
Alternatively, take a look at filter-branch-docs. It has a bunch of options.
Upvotes: 1