I can successfully run git filter-branch
on some code to e.g. merge another repo into a subdirectory [1]:
git filter-branch --index-filter '
git ls-files -s |
perl -pe "s{\t\"?}{$&helper/}" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
' remotes/helper/master
But now, I'd also love to expand each commit's message to include its former ID (SHA hash), since those commits may have had comments/conversation on GitHub which aren't getting transferred over.
E.g. add an extra line like this (where bob/helpers
is hardcoded/known in advance):
[COPIED FROM bob/helpers@76c7c080b3bd2f93dc78e4864899d668a57cd9f9]
As far as I can tell, Git's msg-filter
only gives me the original message, and Git's env-filter
doesn't contain the commit ID (SHA has) as an input variable. Is this possible then, or no?
Thanks!
[1] Via this great article, with the Perl filter from this email thread to workaround a bug on Mac OS X.
To change the most recent commit message, use the git commit --amend command. To change older or multiple commit messages, use git rebase -i HEAD~N . Don't amend pushed commits as it may potentially cause a lot of problems to your colleagues.
Lets you rewrite Git revision history by rewriting the branches mentioned in the <rev-list options>, applying custom filters on each revision. Those filters can modify each tree (e.g. removing a file or running a perl rewrite on all files) or information about each commit.
You use it via git filter-branch --subdirectory-filter name_of_subdir @ . This is useful for extracting the history of a folder into its own repository. Another useful filter is the tree filter, you can use it to do things like moving around, creating, or removing files.
--msg-filter
would be where to do it, and the original commit ID is in the environment variable $GIT_COMMIT
, so (untested) make the message filter simply: cat; echo "[COPIED FROM bob/helpers@$GIT_COMMIT]"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With