Modify file before commit using commit before commit

I am trying to write a pre-commit hook that changes the line in my code, but I don’t even know where to start.

The problem is this:

I have a KEY

 public static final String APP_KEY = ""; //DELETE THE KEY BEFORE COMMIT!!! 

To avoid posting KEY to the repository, I think git hooks are what we need, instead of manually deleting the key. I look at Configuring git hooks , but I don't know how to write a hook.

Is there a way before committing the changes, delete KEy and after committing write the key again?

+7
git githooks pre-commit
source share
1 answer

This will be done with a content filter filter :

  • clean script that will remove the key when checking
  • smudge script that will add it back for verification.

smudge

(Image from Configuring Git Attributes from the Git Book )

See an example of how these filters are declared in. Can Git automatically switch between spaces and tabs? "

+4
source share

All Articles