1

Next command is to store commit history and files lists but remove file contents in order to minimalize disk space and network traffic consumption when need to get know history of huge repo without fetching large objects. This allows to save much time.

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

I also need to know the source commit hash. It is appended to commit message as you can see in --msg-filter part.

I would like to store source commit hash in git notes.

Is it possible? How?

kyb
  • 7,233
  • 5
  • 52
  • 105
  • Aside: you don't need `-not -path ./.git\*` as `--tree-filter` is run in a temporary directory that contains no `.git` directory – torek Nov 07 '18 at 21:00
  • this is not only for .git directory but mostly for .gitignore and .gitattributes – kyb Nov 07 '18 at 21:27
  • Ah, that makes sense, but then you probably should use `-not -name .gitignore -not -name .gitattributes` since such files can occur at any subdirectory. – torek Nov 07 '18 at 21:53
  • and gitmodules and something else ... I prefer pattern, why not? – kyb Nov 07 '18 at 22:14
  • 1
    Well, `.gitmodules` should only occur at the top level, so there `-path` makes sense. The problem with `-path ./.git\*` is that it *won't* recognize `subdir/.gitignore`, for instance, because that isn't path `./.git*`, but rather path `./subdir/.git*`. – torek Nov 07 '18 at 22:30
  • sure. I should use `./\*/.git\*` – kyb Nov 09 '18 at 11:16

1 Answers1

0

Simple solution: do not change commit message, but create file.

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
kyb
  • 7,233
  • 5
  • 52
  • 105