美文网首页
filter-branch

filter-branch

作者: 一江碎月 | 来源:发表于2018-04-01 15:49 被阅读0次

基础

参考
Git pro
环境变量

重置指定分支的 Git 历史记录,同时在每一个提交结点上运用指定的过滤器。

该命令会擦洗整个提交历史。假设使用该命令移除某个文件,则该分支的所有历史提交结点中都不会有该文件存在。

--tree-filter <command>

重写树及其内容。

其中 command 为 shell 命令,如 rm 、touch 等。

任何忽略文件的配置,都不会影响 command 命令中的操作的文件。例如在 .gitingore 中配置忽略所有名为 ee 的文件,但在 command 中又新建了名为 ee 的文件,那么 ee 文件会新建成功,不会受 .gitignore 文件的影响

该命令只会影响指定分支的历史记录。如果想作用在所有分支上,可以给命令传递 --all 选项

$ git filter-branch --tree-filter "echo 'this is from filter-branch' > dd.txt" HEAD
Rewrite 9b335a39f65dff232f239c08baeeb9f7d27f193a (1/16) (0 seconds passed, remai
# 省略一部分
Ref 'HEAD' was rewritten

$ git grep -e "[\s\S]*" HEAD~ -- dd.txt
HEAD~:dd.txt:this is from filter-branch

该命令会重置当前分支的每一个历史结点对应的 tree。并对该 tree 对应的文件夹中运行 echo 'this is from filter-branch' > dd.txt 命令 —— 即生成一个 dd.txt 文件,同时向 dd.txt 中写入 this is from filter-branch


--commit-filter

重置历史记录中的每一个 commit 对象。

例如,可以向每一个 commit 对象统一配置 email 值。

$ git filter-branch -f --commit-filter '
     GIT_AUTHOR_EMAIL="schacon@example.com";
     git commit-tree "$@";
' HEAD

上述命令会将当前分支的所有提交结点的 email 重置为 schacon@example.com

在命令中使用的 GIT_AUTHOR_EMAIL 是 Git 内置的环境变量,具体可以查看环境变量

相关文章

网友评论

      本文标题:filter-branch

      本文链接:https://www.haomeiwen.com/subject/yxfacftx.html