Assume you Git repository contains the following 3 files.
i want to retain the init.conf in the repository for initial checkout. After that, ignore further changes which is made on the local branch.
In the above case, .gitignore doesn’t work because it is only for untracked file which means you have to remove it that file from the Git repository.
Here is a workaround which i found on StackOverflow. On your local branch, execute the following command to set the assume-unchanged bit on a particular <file>.
git update-index --assume-unchanged <file>
This will make your local branch ignore any changes on your tracked files. The drawback is any update of that file on the remote branch would be invisible to your local branch too.
To revert the index, you can use do the following.
git update-index --no-assume-unchanged <file>
To list out those files which the assume-unchanged bit is set, use the following.
git ls-files -v | grep ^h
- StackOverflow – Making git “forget” about a file that *was* tracked but is now “.gitignored”
- StackOverflow – Can I get a list of files marked –assume-unchanged?