Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you tell git to permanently ignore changes in a file?

Tags:

git

I'm working with a git repository that's storing data for a website. It contains a .htaccess file, with some values that are suitable for the production server. In order for me to work on the site, I have to change some values in the file, but I never want to commit these changes or I will break the server.

Since .gitignore doesn't work for tracked files, I was using "git update-index --assume-unchanged .htaccess" to ignore my changes in the file, however this only works until you switch branches. Once you change back to your original branch, your changes are lost.

Is there some way of telling git to ignore changes in a file and leave it alone when changing branches? (Just as if the file was untracked.)

like image 451
Malvineous Avatar asked Apr 20 '10 07:04

Malvineous


People also ask

How do I ignore changes to a file in git?

In the Git Changes window, right-click any changed file that you want Git to ignore and choose Ignore this local item or Ignore this extension. Those menu options don't exist for tracked files.

How do I tell git to ignore a file?

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.

How do I ignore a file in GitHub?

To ignore files in your repository with GitHub Desktop go to the Repository menu and select Repository Settings… With the Repository Settings pop-up open, click the Ignored Files tab. Here you will be able to add file names, directory names, or patterns for Git to ignore in your repository.

How do I ignore a git file without Gitignore?

To ignore untracked files, you have a file in your git folder called . git/info/exclude . This file is your own gitignore inside your local git folder, which means is not going to be committed or shared with anyone else. You can basically edit this file and stop tracking any (untracked) file.


1 Answers

You could use a smudge/clean process (a gitattribute filter driver, described in ProGit)

clean smudge

Each time you update your working directory, you would have the opportunity to replace the content of your .htaccess with a predefined one, correct for your current environment.
In the clean stage, you would then restore the original content, as if you had never touched that file.

like image 196
VonC Avatar answered Sep 28 '22 12:09

VonC