2

Is it possiable to block the specific file type (.dll, .exe) in git commit?

I know we can do this by .gitignore file. But I have more than 500 repo, So It is not easy to add the .gitignore file in every projects.

We can do the same thing by per-receive hook but I get Restrict the specific type file commit in Git.

Any Ideas?

spickermann
  • 100,941
  • 9
  • 101
  • 131
Arunkumar
  • 73
  • 1
  • 11
  • refer this https://stackoverflow.com/questions/17866246/block-specific-file-for-some-users-in-git-repository – Aniket Tiwari Sep 25 '17 at 06:00
  • If the only problem is adding the `.gitignore` file to every repo, you can just use a system-wide `gitignore` or a user-wide `gitignore` instead. – Jörg W Mittag Sep 25 '17 at 06:36
  • 1) a global or system-wide gitignore which ignores `.dll` and `.exe`, 2) a global or system-wide local `pre-commit` which removes the changes of `.dll` and `.exe` from the index, 3) a server-side `pre-receive` to fail any new commit that changes `.dll` or `.exe`. The 3rd makes sure no such commit will be merged into the blessed repository. The 1st and 2nd give quick check and help to users. – ElpieKay Sep 25 '17 at 06:44
  • @ElpieKay I tried 3rd idea [manually](https://stackoverflow.com/questions/46364247/) but it does not work for me! Any suggestion to work the ruby code? – Arunkumar Sep 26 '17 at 11:46
  • I don't know about Ruby. But the `pre-receive` in your link seems not right. `git diff --cached` can't work here. You need to get `old-value`, `new-value` and `ref-name` from the standard input. And then use a command like `git log old-value..new-value --pretty=format:"" --name-only` to get the changed file list. If the list contains any `.dll` or `.exe`, then exit with a non-zero value to fail the push. About `pre-receive`, please see https://www.git-scm.com/docs/githooks.html#pre-receive. – ElpieKay Sep 26 '17 at 12:02

1 Answers1

2

You can create a global .gitignore file.

How to - https://help.github.com/articles/ignoring-files/#create-a-global-gitignore

Open Terminal.

Run the following command in your terminal:

git config --global core.excludesfile ~/.gitignore_global

Community
  • 1
  • 1
geek_guy
  • 607
  • 1
  • 5
  • 17
  • Is it suitable for GitLab? – Arunkumar Sep 25 '17 at 12:24
  • 1
    Yes. It's in your local machine. Doesn't matter which version control website you use. – geek_guy Sep 25 '17 at 12:34
  • Well, I have an another doubt, That is If I do the same thing in my gitlab server machine means, will it work or not? Also Is this work globally or the single user who configures the `gitignore` (It's in your local machine)? – Arunkumar Sep 26 '17 at 04:20
  • This ll work wherever your configure .gitignore file. If you have multiple users, a better solution is to put it at the project level. – geek_guy Sep 26 '17 at 07:28
  • 1
    Will this prevent use of the ```commit -f``` flag? – MarkTO Sep 04 '20 at 17:46