【问题标题】:Add note to commit when filtering branch with Git使用 Git 过滤分支时添加注释以提交
【发布时间】: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


【解决方案1】:

简单的解决方案:不要更改提交消息,而是创建文件。

git filter-branch -f -d `mktemp -d` \
   --tree-filter '
      find . -type f -not -path ./\*/.git\* |
         while read file; do > "$file"; done
      echo "$GIT_COMMIT" >.GIT_COMMIT
   ' \
   -- metainfo/$BRANCH

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 2011-05-30
    • 2013-08-18
    • 2013-01-15
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    相关资源
    最近更新 更多