Ignore local changes in the file and update it on pull

406 Views Asked by At

We have a repo with a file say x.APK that is pulled by client machines.
These client machine will modify this file and keep it locally for their use.

In normal usage we will update this file very rarely say once in 2-3 months.
The first time it will pull the files many along with x.APK and modify it and store it locally. We then update other files and push. On pull in client we get a local change but since x.APK did not change there are no conflicts.
Now is there any way to update x.APK ignoring whatever local changes were made to that file with only git pull.

git pull are done by a script and we cannot access the clients always. so running other commands will be tricky.

We tried:

git update-index --assume-unchanged

this ignores the changes but is not able to pull

Using gitignore it will delete the file from the clients and repo which we don't want.

It is a peculiar case if someone could help out it would be great.

1

There are 1 best solutions below

8
On

It depends on the nature of the local modification done in x.txt.

If those modifications are well defined (and not all over the place in x.txt) then you could consider a content filter driver in order to generate the right x.txt on checkout:

  • it means that you do not version x.txt anymore, but a template version "x.template".
    git mv x.txt x.txt.tpl.
    Add x.txt to your .gitignore.

  • Then, add a smudge script associated to x.txt files in a .gitattributes declaration:

    x.txt filter=updatex
    

smudge
(image from "Customizing Git - Git Attributes", from "Pro Git book")

git config filter.updatex.smudge 'update_x'

The style_smudge script can be versioned, and will have to fetch local modification content from a file outside the repo (meaning those a private modification), and inject its content in the template in order to generate the actual x.txt.

That way, a git pull which triggers an update of the working tree would automatically re-generate x.txt with the new updates as well as the local modifications.