Situation
I am putting htm files into git. Then I'm using git diff to compare them. There are differences between the files that I'm not interested in, such as meta or comments tags.
I'm using this approach generally: How to tell git to ignore individual lines, i.e. gitignore for specific lines of code
What I've Done So Far
Here are the steps I've taken:
<project root>/.gitattributes
*.htm filter=gitignore
, i.e. run filter gitignore on all .htm files $ git config --global filter.gitignore.clean "sed 's/<meta.*>//g'"
, i.e. delete these
lines $ git config --global filter.gitignore.smudge cat
, i.e. do
nothing when pulling file from repogit diff A..B -- file.htm > diff.txt
Depending on which branch I'm currently on, I get different results:
The Question
How can I make it so that regardless of which branch I'm on ALL branches get that filter applied to them?
These filter do not care about the branch you are on. Similarly, git diff A..B -- file.htm
will not depend on the current branch, as you are specifying git repository trees via the branch heads (commits) A and B directly.
Quoting man git-config
filter.<driver>.clean: The command which is used to convert the content of a worktree file to a blob upon checkin.
filter.<driver>.smudge: The command which is used to convert the content of a blob object to a worktree file upon checkout.
So your sed script is only run when you "add a file to git". It does not alter existing commits and should not affect a diff between them. It looks like the meta tags are still present in the files of your branch B, because they were added before you configured your filters.
If you can still modify branch B, you might try the following after making a backup.
find . -name \*.htm -exec rm {}
git checkout B
git reset --hard
Your repository should now show removals of meta tags to 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