该部分内容会改变历史信息,慎重使用。核弹级应用
替换邮件,作者:
1 git filter-branch-f --env-filter "GIT_AUTHOR_NAME='Newname'; GIT_AUTHOR_EMAIL='newemail';GIT_COMMITTER_NAME='Newname'; GIT_COMMITTER_EMAIL='newemail';" HEAD
GIT_AUTHOR_NAME,GIT_AUTHOR_EMAIL, GIT_AUTHOR_DATE,GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL,GIT_COMMITTER_DATE
gitfilter-branch --env-filter '
if test"$GIT_AUTHOR_EMAIL" = "root@localhost"
then
exportGIT_AUTHOR_EMAIL
fi
if test"$GIT_COMMITTER_EMAIL" = "root@localhost"
then
exportGIT_COMMITTER_EMAIL
fi
' -- --all
2 从所有提交中删除文件(包含机密信息或版权违反)
git filter-branch --tree-filter 'rm filename' HEAD(范围区间)
gitfilter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
3 重写提交消息
gitfilter-branch -f --msg-filter 'sed -r "s/\[PIS-[0-9]+\]//g; s/\[TAIDOM-[0-9]+\]//g;s/XT1706/Taido/g" ' ${oldest_sha1}~1..HEAD
gitfilter-branch --msg-filter 'sed -e "/^git-svn-id:/d"'
gitfilter-branch --msg-filter 'cat && echo "Acked-by: Bugs Bunny
4 重写tag名称
gitfilter-branch --tag-name-filter
5 单独分离该库底下的DIR子目录。即新库目录下只有DIR这个目录
gitfilter-branch -f --prune-empty --subdirectory-filter DIR
6 项目根目录改成trunk子目录。放弃其它历史
gitfilter-branch --subdirectory-filter trunk HEAD -- --all
--all 重写所有的branches和tags
https://segmentfault.com/q/1010000000250171
7 将提交设置为当前初始提交的父级,以便在当前历史后面粘贴其他历史记录.
gitfilter-branch --parent-filter 'sed "s/^\$/-p
gitfilter-branch --parent-filter \
'test $GIT_COMMIT =
或 echo "$commit-id $graft-id" >> .git/info/grafts
git filter-branch $graft-id..HEAD
8 从历史除去“Darl McBribe”撰写的提交:
gitfilter-branch --commit-filter '
if ["$GIT_AUTHOR_NAME" = "Darl McBribe" ];
then
skip_commit"$@";
else
git commit-tree"$@";
fi' HEAD
skip_commit()
{
shift;
while [ -n "$1" ];
do
shift;
map "$1";
shift;
done;
}
10. D--E--F--G--H
/ /
A--B-----C
仅重写D,E,F,G,H,不修改 A, B and C: git filter-branch ... C..H
仅重写E,F,G,H: git filter-branch ... C..H --not D
gitfilter-branch ... D..H --not C
记住哦,git的使用经常都是左开右闭
11. 整个数目录变成子目录:
git filter-branch --index-filter \
'git ls-files -s | sed"s-\t\"*-&newsubdir/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
gitupdate-index --index-info &&
mv"$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD