As kind of a followup of this question I have a git repository with the following directory structure
conferences
├── conferenceA
│ └── proceedings
├── conferenceB
│ └── proceedings
└── conferenceC
└── proceedings
and I want to create a new repository which contains only the content of conferenceA without the proceedings.
So I drafted a shell script in conferenceA which does
cd $(git rev-parse --show-toplevel)
tmp=$(git subtree split --prefix=conferenceA)
git filter-branch --index-filter 'rm -rf proceedings' $tmp
git push conferenceAslides $tmp2:master --force
Which hase multiple problems:
- after rewriting the history with filter-branch, new commits are created of which I don't know the hash to fill
$tmp2 filter-branchdoes not accept a hash as argument for me
:
pseyfert@computer > git filter-branch --tree-filter 'rm -rf proceedings' -- $tmp
Which ref do you want to rewrite?
As far as I understood the git-filter-branch reference, the argument of what to filter, should be the same as for git rev-list and there the $tmp hash seems fine to me (git rev-list $tmp and git checkout -b test $tmp; git rev-list test appear to give the same output)
So my question is: How to I use git filter-branch without assigning a branch name? Is there a different command I should use?
After the rewrite, the next thing your script would do is push the rewritten commit's hash to
master. That means you're rewriting the history ofmaster, so why not just tellfilter-branchto rewritemaster?To put it another way: the 2nd "problem" isn't a problem; it's the solution to the 1st problem. Yes, if
filter-branchlet you rewrite an arbitrary SHA-ID, the result would be an unreachable commit whose ID you don't know; so insteadfilter-branchrewrites from a ref and then moves the ref so you can find the rewritten commits by going to the ref.