I would like to add a gitignore filter for a specific lines of the code. Here is the solution.
It requires calling appropriate git config
command. When some other user clones that repo the filtering doesn't work unless git config
command is called. I need a solution where after cloning a repository filtering works without any additional actions. How to solve that problem ?
Asked
Active
Viewed 39 times
0

Irbis
- 1,432
- 1
- 13
- 39
-
Tell your users to use a script that you write, that runs `git clone` followed by the appropriate `git config`. They should run this script *and not run `git clone` at all*. That's the only way to make it work with a single command. Note that **Git will never, on its own, run scripts it just downloaded** as **this would be a horrible security hole**. – torek Jun 01 '20 at 00:48
1 Answers
0
You need git hooks. Git hooks are scripts that Git executes before or after events.
The post-checkout hook also runs on git-clone
(when run without --no-checkout
).
It is also run after git-clone, unless the --no-checkout (-n) option is used. The first parameter given to the hook is the null-ref, the second the ref of the new HEAD and the flag is always 1.

SwissCodeMen
- 4,222
- 8
- 24
- 34
-
I need a pre-commit hook which ignores a particular lines of the code but hooks are not pushed to the repository. It looks like it doesn't solve my problem, – Irbis May 31 '20 at 20:18
-
post-checkout: "Run when a checkout is called after updating the worktree or after git clone. It is mainly used to verify conditions, display differences, and configure the environment if necessary." Now you an write your [solution](https://stackoverflow.com/questions/16244969/how-to-tell-git-to-ignore-individual-lines-i-e-gitignore-for-specific-lines-of) in the git-hook... – SwissCodeMen May 31 '20 at 22:11