Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git doesn't ignore 2 specifically named files

Tags:

git

gitignore

I want to automatically exclude 2 files from committing, that are part of the git repository but have some changes, that shouldn't be part of the github repo, because they have some changes that are only meaningful to my local system and not the other developers.

I added them to .git/info/exclude in the hopes git understands that he shouldn't commit changes to them:

# git ls-files --others --exclude-from=.git/info/exclude # Lines that start with '#' are comments. # For a project mostly in C, the following would be a good set of # exclude patterns (uncomment them if you want to use them): # *.[oa] a.conf b.conf # *~ 

but git status still lists them as staged for committing:

# On branch master # Changes to be committed: #   (use "git reset HEAD <file>..." to unstage) # #   modified:   build/conf/a.conf #   modified:   build/conf/b.conf # 

I don't want to unstage them regularly with every commit (one time I might just forget), how can I do that?

like image 546
erikbstack Avatar asked Jun 04 '12 10:06

erikbstack


People also ask

Why is Gitignore not ignoring my files?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.

How do I not ignore a specific file in Git?

Git ignore patterns An asterisk is a wildcard that matches zero or more characters. Prepending an exclamation mark to a pattern negates it. If a file matches a pattern, but also matches a negating pattern defined later in the file, it will not be ignored.

Why Git ignore file is not working?

Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.


1 Answers

What you want to is to ignore changes on tracked files. This cannot achieved (as Charles Bailey says) correctly, neither with .gitignore nor with .git/info/exclude.

You'll need to use git update-index:

git update-index --assume-unchanged build/conf/a.conf git update-index --assume-unchanged build/conf/b.conf 

will achieve what you want: the files are always assumed unchanged.

If you want to track changes in these files again, use --no-assume-unchanged.

Finally, if you want to know which files are currently in the --assume-unchanged mode, ask git for

git ls-files -v | grep -e "^[hsmrck]" 
like image 138
eckes Avatar answered Oct 13 '22 05:10

eckes