Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is git ignoring my changed file?

Tags:

git

gitignore

I make an arbitrary change to a file within my git working directory.

git status does not recognized that the file has changed.

git add /path/to/file has no effect.

git add -f /path/to/file has no effect.

git status /path/to/file shows the file as in the 'changes to be committed' bucket.

I removed my .gitignore file, just to be sure. No change to any of the above behaviors.

I have done git reset --hard, re-made my change. No change to any of the above behaviors.

What could be going on here?

like image 353
joshwa Avatar asked Aug 25 '09 16:08

joshwa


People also ask

How do I stop git from ignoring files?

gitignore file will not untrack them -- they will remain tracked by Git . To untrack files, it is necessary to remove from the repository the tracked files listed in . gitignore file. Then re-add them and commit your changes.

How do I stop git from tracking and ignoring changes?

Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.

Why do we ignore files in git?

When Do You Use Git Ignore File? The git ignore file rule allows you to ignore a file you've committed in the past. You use it when you do not want to recommit a file, for example a build artifact.

Is .git folder ignored by default?

git folder is ignored by default. All others are deamed potentially important for the source-base unless configured otherwise within the repository or at a global level.


2 Answers

Also make sure that you have not manually updated the index to assume that the changed file(s) are unchanged like so:

git update-index --assume-unchanged path/to/file

As dumb as it sounds I did that, then a few days later made changes to the file and could not figure out why git was not tracking it. I tried all of the above suggestions, and kept pulling my hair out b/c the changed file was not listed in any .gitignore or exclude files.

If you've told git to assume the file is unchanged, you will have to:

git update-index --no-assume-unchanged path/to/file

or just re-clone the repo like I ended up doing before I remembered what I had done...

like image 168
Tom Wayson Avatar answered Oct 14 '22 00:10

Tom Wayson


Turns out I added skip-worktree on my file [1]

git update-index --skip-worktree path/to/file

and forgot. You can undo this with:

git update-index --no-skip-worktree path/to/file

ls-files with -v revealed the status of the file in my case:

git ls-files -v | grep path/to/file
S path/to/file

The letters git ls-files -v will prefix with are and mean:

# H: cachead
# S: skip-worktree
# M: unmerged
# R: removed/deleted
# C: modified/changed
# K: to be killed
# ?: other
# lowercase letter: assume-unchanged

To identify your issue

Is the file ignored by git?

git check-ignore * **/* | grep path/to/file
git ls-files --exclude-standard --ignore

If the file is listed, there is an ignore rule somewhere that is excluding it.[2] [3] Find it in one of these files:

less .gitignore
less ~/.gitignore
less %USERPROFILE%\.gitignore # <- Probably the same file as the above one
less $( git config --global core.excludesfile )
less $( git config --system core.excludesfile )
less ${GIT_DIR:-.git}/exclude

Is the file flagged assume-unchanged

git ls-files -v | grep path/to/file

If the file is prefixed with a lower case letter, it is flagged with assume-unchanged. Fix it with:

git update-index --no-assume-unchanged path/to/file

Is the file flagged skip-worktree

git ls-files -v | grep path/to/file

If the file is prefixed with S, it is flagged with skip-worktree. Fix it with:

git update-index --no-skip-worktree path/to/file
like image 43
Nate Avatar answered Oct 13 '22 23:10

Nate