-1

Can git update a file but not track it?

I have a big .pdf file in that I often update. I'd like to add it in my repo and have it updated when my collaborators run git pull but I don't want changes to be tracked (because of disk space reason). Is it possible?

I want to modify my .pdf file and I want it to be updated when I push my commits, but I don't want changes to the file to be tracked.

  • 2
    Does this answer your question? [Keep file in a Git repo, but don't track changes](https://stackoverflow.com/questions/9794931/keep-file-in-a-git-repo-but-dont-track-changes) – dejanualex Feb 19 '21 at 10:11
  • No. I want to modify my `.pdf` file and I want it to be updated when I `push` my commits, but I don't want changes to the file to be tracked. – Gabriele Nicolardi Feb 19 '21 at 10:21
  • 1
    Git does not track changes. It _stores files_. The storage wrapper of files at a moment in time is a _commit_. Git traffics solely in commits — not files, not changes. If you make git aware of a file by storing it in a commit, you have stored the file. Your whole idea is nonsense as regards Git. – matt Feb 19 '21 at 10:34
  • @matt, Thanks. I just need to know this. – Gabriele Nicolardi Feb 19 '21 at 10:43

1 Answers1

3

These seem to be conflicting demands:

  • you want the latest version to always be available in your repository
  • you don't want to keep all versions
  • you want to keep the history of all other files (which ideally should not change).

Here are some ideas that might possibly help you on your way:

rewrite history

You could however rewrite your history to remove the pdf file from the history, but then your complete history would need to be rewritten (regularly?) to keep the repository size small. This will then break your history and synchronization with colleagues will be broken, since all commit hashes will change, and it will be very complicate for them to keep in sync with you.

separate branch

An alternative approach might be to just store the pdf in a special branch "pdf" with a single commit. You can then always just rewrite that commit and keep all other history intact. But this would make it relatively complicated for your team members to get the latest version of the pdf.

other ideas

Investigate these alternatives:

  • store the pdf elsewhere than in git
  • can the pdf be generated from code? In that case store the code in git, not the end result
Chris Maes
  • 35,025
  • 12
  • 111
  • 136