I am experimenting with git filter-branch
, and I found out that this command:
git filter-branch --prune-empty --subdirectory-filter directory -- --all
apparently works equally well without the --prune-empty
switch. The manpage says this:
--subdirectory-filter <directory>
Only look at the history which touches the given subdirectory. The result will contain that directory (and only that) as its project root.
I find it a little ambiguous. Does that mean that if a commit does not touch the directory
, it will be omitted from the result (even if --prune-empty
was not given)?
I am not that well-versed in shell scripting to be able to figure it out quickly from the source code (git-filter-branch
is written in sh
), so I would appreciate any comments from more experienced people, preferably with the relevant part of the source cited.
In the case anyone would like to perform an experiment similar to my one, here are the commands I use (I use bash, though I am pretty sure this is shell-agnostic).
cd /tmp
rm -rf repo
git init repo
cd repo
mkdir directory
echo "some file in the root dir" > some-file.txt
echo "another file in the directory dir" > directory/another-file.txt
git add .
git commit -m "Initial commit"
echo "added line" >> directory/another-file.txt
git commit -am "Add a line"
echo "An an unrelated commit" >> some-file.txt
git commit -am "An an unrelated commit"
echo "A commit spanning everything" >> some-file.txt
echo "A commit spanning everything" >> directory/another-file.txt
git commit -am "Make huge changes"
git filter-branch --prune-empty --subdirectory-filter directory -- --all