git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: efficient way to filter several branches with common history?

From
Steffen Prohaska <prohaska@zib.de>
Date
Jul 4, 2007, 13:27 UTC
Message-ID
<6DC0E50A-CAD3-453E-BD9C-73E51EDD5785@zib.de>
In-Reply-To
<468B5C4B.26F5E90B@eudaptics.com>
On Jul 4, 2007, at 10:37 AM, Johannes Sixt wrote:
Show 25 quoted lines
> Steffen Prohaska wrote:
>>
>> Is there an efficient way to filter several branches at once
>> through git-filter-branch? Often several branches have a lot
>> of common history. Therefore, I suspect it would be much more
>> efficient to filter them with one call to git-filter-branch.
>> For example how can I efficiently filter all origin/* branches
>> to filtered/* branches?
>
> That feature is not yet implemented.
>
> In the meantime do it this way:
>
> Make an octopus merge of the branches onto a new branch. (If you have
> more than a dozen or so, you better make a hierarchy of  
> octopusses.) You
> don't need to resolve conflicts (you are not interested in the merge
> result), or use -s ours to avoid them in the first place.
> Then filter that new branch.
> Then create new refs at the rewritten commits:
>
>    $ git update-ref refs/filtered/b1 $id-of-rewritten-origin/b1
>    $ ...
>
> Use gitk to find the $ids-of-rewritten-origin/*

Thanks for your explanation. The following is the template I used to build my fully automated version of what you proposed:

--- SNIP --- echo "merging branches to be filtered ..." git-checkout -b tmp/all origin/master

for b in origin/branchX origin/branchY [ ... more branches here ...]
do
     git merge -s ours -m "merge-for-preparing-filter-branch $b" $b
done
echo "... filtering ..."
git-filter-branch \
[... your git-filter-branch filters here ...] \
   filtered/all >filter-branch.log
echo "... setting heads of filtered branches."
lastp1=
git-log --pretty="format:%s %P" filtered/all |
while read t b p1 p2
do
     [[ "$t" == "merge-for-preparing-filter-branch" ]] || { git  
update-ref refs/heads/filtered/master $lastp1 ; break ; }
     b=filtered/$(basename $b)
     git update-ref refs/heads/$b $p2
     lastp1=$p1
done

echo "delete tmp/all and filtered/all after checking the result" --- SNIP ---

	Steffen
Previous: Johannes SixtNext: Johannes Schindelin
Message 3 of 4 in “efficient way to filter several branches with common history?”
  1. Steffen ProhaskaJul 4, 2007
  2. Johannes SixtJul 4, 2007
  3. Steffen ProhaskaJul 4, 2007
  4. Johannes SchindelinJul 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.