2

I often find myself commiting with git add -f binary files which are in .gitignore (.exe, .pdf, ...), just to include a stable, working, compiled file in the history, so I can at least use it even if I have problems compiling it again (eg. because of a missing library on another computer).

$ cat .gitignore *.exe *.pdf $ git add -f program.exe documentation.pdf $ git commit -m "Added working .exe and .pdf" $ gcc program.c -o program.exe $ pdflatex documentation.tex # Generates documentation.pdf $ git status --short M program.exe M documentation.pdf 

Now that I've added the .exe and .pdf, I'd like that future modifications to them be ignored. Otherwise, each time I do git commit -a these files are automatically included.

2 Answers 2

5

You can use the --assume-unchanged option here the manpage.

git update-index --assume-unchanged program.exe documentation.pdf 

In this way those files aren't added to the index.

Sign up to request clarification or add additional context in comments.

Comments

2

There is no point to store binaries in a same repo as source code, as it will create problems - rapidly growing repo size, problem during merges, slower operations. The better if you create another repo and store files with versions. It is called binary repository. You even don't need have a proper VCS repo, just a set of folders named after version number, e.g. http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/

Another option is to use git notes. In a man-page you could find a way to attach any binary file to any object in the repo.

4 Comments

I know about all these problems, that's why I want git to ignore changes to these files. But when you have compiled your .tex file to a .pdf (say, a presentation), and you go on another computer, checkout the repo, and find out you can't re-compile your .tex due to missing packages, and your presentation starts in 10 minutes, then you're glad when you have commited the .pdf in your repo. That saved my neck multiple times. And since I only commit one or two stable versions of the .pdfs, .exes or linux binaries, they don't add much to the repo size, and won't participate to merges.
@GeorgesDupéron Why just not upload the binaries on a ftp server (or scp, or dropbox, or google drive or something like that)? If would work faster at least. You could make a simple shell-script or makefile which compiles your binaries and deploys them on a ftp.
Okay, put the question another way: How can I add files attached to a specific revision of a git repo, so that whenever I run git push, git clone, git pull, or even git bundle, those files are sent and recieved too? Answer: just commit them, duh. I don't want to have two different commands to commit source files and binaries, it's a very good way to forget to run one of them, plus the burden of tracking which file belongs to which revision. Note that I'm talking about small repos with a dozen files and tens of revisions. I wouldn't do that on repo with thousands of files & revisions.
@GeorgesDupéron You reminded me one option - notes. Answer updated

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.