17

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?

joshwa
  • 1,660
  • 3
  • 17
  • 26
  • When you say '/path/to/file' I assume that either you don't really mean an absolute path, or the absolute path really does lead back to your git working directory? What does `git show HEAD:path/to/file` show? – CB Bailey Aug 25 '09 at 18:32
  • my problem was that i forgot about my previous commit, just needed to `git diff HEAD~1` and `git add .` and `git commit --amend --no-edit` – neaumusic Mar 02 '15 at 19:38

9 Answers9

33

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...

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Tom Wayson
  • 1,187
  • 1
  • 12
  • 21
21

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
Community
  • 1
  • 1
Nate
  • 12,963
  • 4
  • 59
  • 80
  • What do those `|` characters do? – Thomas Oct 06 '15 at 19:46
  • That's a [bash pipe](http://stackoverflow.com/a/9834118/761771). It takes the output of the command to the left and gives it as input to the command on the right. `ls | sort` for example will pipe the list of files from `ls` into `sort` that sorts them and prints the sorted list. It works basically the same in the Windows shell. – Nate Oct 07 '15 at 18:47
10

There are two general reasons why Git will ignore a file: gitignore and submodules.

To be more specific, the following conditions will cause Git to ignore a file when 'git add' is invoked:

  1. The file matches a pattern in $GIT_DIR/exclude.
  2. The file matches a pattern in a .gitignore file inside the repo.
  3. The file matches a pattern in a user-specific .gitignore file (specified by 'git config --global core.excludesfile').
  4. The file is part of a submodule.

More info can be found in another SO question:

Unable to track files within Git submodules

Community
  • 1
  • 1
Tim Henigan
  • 60,452
  • 11
  • 85
  • 78
6

Check using

$ git ls-files --exclude-standard --ignore

if the file is truly not excluded (there are other exclude files than only .gitignore).

Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
4

You check your global git ignore file?

git config --global --get-all core.excludesfile
git config --system --get-all core.excludesfile

If either of those return a file as their value, look in that file.

davetron5000
  • 24,123
  • 11
  • 70
  • 98
  • 1
    neither of those commands returned a value. To answer my own question, I managed to get them to commit by doing 'git commit /path/to/file', and could do a patch commit by doing 'git rebase -i HEAD~2' and editing the commit. Still no idea why they were being ignored in the first place. – joshwa Aug 25 '09 at 16:40
2

if your file is in the 'Changes to be committed' bucket then git already recognized the change and is going to commit it! Its in the index already. Otherwise it would be in the 'Changed but not updated' bucket.

:)

Hope this helps/

Vitaly Kushner
  • 9,247
  • 8
  • 33
  • 41
  • This is not true if this is the result of a `git status ` command. In this case `git status` is showing what would be committed if you supplied the given parameters to git commit. With an explicit path, any changes are added and committed in one go, it makes no differences if they were staged or not. – CB Bailey Aug 25 '09 at 18:29
1

Are you sure that your file is not excluded by some of the .gitignore files in parent directories?

hlovdal
  • 26,565
  • 10
  • 94
  • 165
0

After you did git add, did you do a commit so it's actually in the repo and can be compared to the (changed) working copy?

kajaco
  • 2,547
  • 3
  • 24
  • 33
0

Check each parent directory from the file in question to the project root for .gitignore files.

Some projects use several .gitignore files, each in its own directory, instead of a single .gitignore in the root.

nostromo
  • 1,435
  • 2
  • 17
  • 23