I am working on a C project which generates lots of binaries. I try to keep the source under source control. However, I would like the binaries to be ignored without having to add them to the gitignore file whenever I create a new one. This is a sandbox of sorts and so I create lots of new binaries as I try out new things. I could build all my binaries in a single directory or give them a suffix, but I dislike these reasons. Since GCC automatically sets the executable bit on the binaries it produces, can I use that flag to ignore them?
Git Tracks ONLY the Executable Bit of the Permissions for the User Who Owns the File.
Yes, by default, git is configured to track the changes in file permission mode, too. Just to experiment with the idea, I created a dummy repo and "touched" an empty file. The initial default permission was 775.
I recommend against this. What happens if you need to use a script in your build process or at runtime, but it's accidentally gitignored because it has the executable bit? This could especially create confusion if other people contribute to your project without knowing about the gitignore. You're best off manually adding files (or using a bin directory) to solve this problem.
That being said, gitignore does not seem to support mode-based file ignores, but you can automate the process of manually adding files that are executable.
If your .gitignore
file can be overwritten:
Run this to update your ignored files: find -type f -executable | sed 's#^.##' > .gitignore
If your .gitignore
file should be kept intact:
.gitignore
should still work): git config core.excludesfile .auto_gitignore
find -type f -executable | sed 's#^.##' > .auto_gitignore
.auto_gitignore
if you want to share it with others, or add .auto_gitignore
to .git/info/exclude
if you don't. Note that if you do share it, your collaborators will also have to do step 1 individually.Note: If you get an error because your version of find doesn't support -executable
, replace it with -perm /111
.
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