gitgit-filter-branchgit-notes

Add note to commit when filtering branch with Git


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?


Solution

  • 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