【发布时间】:2019-04-11 08:38:18
【问题描述】:
下一个命令是存储提交历史记录和文件列表,但删除文件内容,以便在需要了解大型 repo 的历史记录而不获取大型对象时最小化磁盘空间和网络流量消耗。 这样可以节省很多时间。
git filter-branch -f -d `mktemp -d` \
--tree-filter '
find . -type f -not -path ./.git\* |
while read file; do > "$file"; done
' \
--msg-filter '
cat - && echo && echo "commit $GIT_COMMIT"
' \
-- metainfo/$BRANCH
我还需要知道源提交哈希。如您在--msg-filter 部分中所见,它被附加到提交消息中。
我想将源提交哈希存储在git notes。
有可能吗?怎么样?
【问题讨论】:
-
旁白:你不需要
-not -path ./.git\*,因为--tree-filter在一个不包含.git目录的临时目录中运行 -
这不仅适用于 .git 目录,而且主要适用于 .gitignore 和 .gitattributes
-
啊,有道理,但是你可能应该使用
-not -name .gitignore -not -name .gitattributes,因为这样的文件可以出现在任何子目录中。 -
还有 gitmodules 和其他东西......我更喜欢模式,为什么不呢?
-
好吧,
.gitmodules应该只出现在顶层,所以-path是有意义的。-path ./.git\*的问题在于它不会识别subdir/.gitignore,例如,因为那不是路径./.git*,而是路径./subdir/.git*。
标签: git git-filter-branch git-notes