I need to ignore files in git! I don't think ignore is the right word actually; I want the files to be in git, but I don't want to be able to commit changes to them. This may seem like a weird thing to some, but there are many, many instances that I need this functionality. The one instance I need it for now is when using git with a CMS; the CMS won't work without files that it is constantly changing, but I don't want those files to ever be committed after the initial commit. (This is very easy to do with SVN and Tortoise).
WorkFlow:
Here is what I've tried:
.gitignore
-- the files never enter git. If the file is already in cache the .gitignore file doesn't do anything./.git/info/exclude
-- same problem as .gitignore, but only for the local repo.Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
gitignore will prevent untracked files from being added (without an add -f ) to the set of files tracked by Git. However, Git will continue to track any files that are already being tracked. The removal of the file from the head revision will happen on the next commit.
Here is my answer from a similar question.
git update-index should do what you want
This will tell git you want to start ignoring the changes to the file
git update-index --assume-unchanged path/to/file
When you want to start keeping track again
git update-index --no-assume-unchanged path/to/file
Another solution is to use a pre-commit
hook. See git help hooks
for details.
This is harder to set up: you have to write a shell script to express exactly what you want to allow or disallow, which probably means you need to have a fairly good grasp of git.
It's more permanent and flexible: with tricks like git update-index
you can accidentally forget to run it, etc. But once you set up a hook, you never have to worry about it again.
Like the other tricks suggested, hooks don't automatically get propagated between repositories, but you can check them in as regular files and have everyone link them into .git/hooks
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With