How can binary files be ignored in git
using the .gitignore
file?
Example:
$ g++ hello.c -o hello
The "hello" file is a binary file. Can git
ignore this file ?
How can binary files be ignored in git
using the .gitignore
file?
Example:
$ g++ hello.c -o hello
The "hello" file is a binary file. Can git
ignore this file ?
If you're using a makefile, you could try modifying your make rules to append the names of new binaries to your .gitignore file.
Here's an example Makefile for a small Haskell project;
This makefile defines a rule for creating executables out of Haskell code. After ghc is invoked, we check the .gitignore to see if the binary is already in it. If it isn't, we append the name of the binary to the file.
Your best bet with binaries is to either give them an extension that you can easily filter out with a standard pattern, or put them into directories that you can filter out at the directory level.
The extension suggestion is more applicable in Windows, because extensions are standard and basically required, but in Unix, you may or may not use extensions on your executable binaries. In this case, you can put them in a bin/ folder, and add
bin/
to your .gitignore.In your very specific, small-scope example, you can just put
hello
in your .gitignore.I don't know any other solution but adding them one by one to
.gitignore
.A crude way to test is to grep the file command's output:
EDIT
Why don't you simply name you executable
hello.bin
?Just add
hello
or/hello
to your .gitignore. Either works.I created a .gitignore file with two entries in GOPATH directory.
It ignore all the compiled developments, currently.