Git Ignore Current Changes in a File

Recently, I was working on a Web project where the HTML page referenced external JavaScript files – a quite common scenario. The development/testing and the live version of the project were on the same server and used the same socket for hosting. This was on an enterprise platform where these constrains were operationally fixed. So, the HTML page where I was doing the development work pointed to different JavaScript files (development JS files) than did the HTML file located in live repo (the live JS files). This difference – the location of the external JS files (development vs. live) – would always exist between the two repos, and I wanted to ignore this difference so I can use the two git repos to work on and maintain the project.

While the only difference between repositories was the one mentioned above, I issue the following command to ignore the differences.

git update-index --assume-unchanged

Now when I issued a git diff command, git responds by saying there are no changes. With this setup, I can commit changes to the JavaScript files without committing the the HTML file pointing to the development JS files. This way I can push the changes to the JS files to a 3rd, authoritative, repository that the live branch pulls from to stay up to date.

If I want to work on the HTML file – which will be far less frequent – I issue the following command (in the development repo) to resume tracking changes in the file.

git update-index --no-assume-unchanged

I just need to be disciplined in remembering that I’m ignoring the changes in the HTML file and switching the src tags to point to the live JS files when I commit changes to the authoritative git repository.

Leave a Reply

Your email address will not be published. Required fields are marked *