On 19-02 03:21, Jan Janak wrote:
But there is a solution: git-filter-branch. This is a
handy git command which
(among other things) can walk through all commits in the history of the
current branch and tranform the commits into new commits with selected files
only. To include only files in modules/sqlops we can do the following:
git-filter-branch --subdirectory-filter modules/sqlops
The command rewrite the history of the current branch, your current branch
should be sqlops_filtered if you followed this guide from the beginning. If
you investigate the history of the branch with git log, you should see only
commits that are related to files in modules/sqlops. (The module contained
only one commit at the time of writing of this memo so don't be surprised if
you only see one commit in the history).
If you examine your current working directory now, you'll notice that the
directory contains files from modules/sqlops in the top level directory. We
need to put them back into modules/sqlopts before we can merge the branch into
sip-router tree, this can be done with git-filter-branch again. But before we
can run the command second time, we need to remove some residual files from
the previous run:
rm -rf .git/refs/original
And the following command will move all the files back to modules/sqlops
subdirectory:
git-filter-branch --index-filter 'git ls-files -s |
sed "s-\t-&modules/sqlopt/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
The previous command might look a little scary, but it is documented in man
git-filter-branch if you are interested in details.
Attached is a simple shell script which does both git-filter-branch commands
described above, I call the script git-filter-move. The script takes two
parameters, the first parameter is the directory filter. The second parameter
is the new prefix of all files that are left after the filter.
So, If I wanted to extract just the kamailio db_berkeley module and if I
wanted to prefix all files in that module with km_ to avoit conflicts with
files coming from ser, I would do:
git co -b bdb_filtered kam/trunk
git-filter-move modules/db_berkeley modules/db_berkeley/km_
And after this the branch is ready to be merged into other branches. Note that
if you just wanted to extract a module without giving its files km_ prefix,
you would run:
git-filter-move modules/db_berkeley modules/db_berkeley/
Notice the trailing / in the second parameter, it is important in this case.
Jan.