12

For a project I'm working on, I want to use:

git add . -A

to add some files to the stage. The problem is that Git thinks these files are unchanged from the last commit, so they are ignored. However, I personally changed the file, but Git still sees the file as unchanged.

How can I "forcefully" add that single file to my repository?

random
  • 9,774
  • 10
  • 66
  • 83
user2744374
  • 121
  • 1
  • 1
  • 3
  • By any chance, is the file gitignored. See if there's a .gitignore file and an entry in there, for this file. – Sruti Sep 03 '13 at 20:12
  • No, the filetype is not in my .gitignore. – user2744374 Sep 03 '13 at 20:59
  • There's an old SO question : http://stackoverflow.com/questions/9707562/git-is-not-detecting-a-file-and-is-not-in-gitignore. Have you tried these? – Sruti Sep 03 '13 at 21:38
  • My problem is different from theirs, Git will recognize when I have deleted or renamed the file, but I need it to always have the same name. I just can't get Git to add my file because it thinks the file is unchanged. Even if the file is truly unchanged, Git should still let me add it and eventually commit it. – user2744374 Sep 03 '13 at 21:53
  • No, I don't think it will do that. Because git commits are hashes of the content and it will think there are no changes if current changes hash to the same hash value as the head. – Sruti Sep 03 '13 at 21:59
  • In fact, try deleting a file and adding the same file again. Git will think no changes! – Sruti Sep 03 '13 at 22:02
  • If the file is in fact unchanged (e.g., if you've removed it from the work tree, then put back a bit-for-bit-identical "new" version), then the file *is* unchanged and does not need to be added to the staging area as it is already *in* the staging area and will be in the next commit. – torek Sep 03 '13 at 22:08
  • 1
    Sidenote: It is generally a bad idea to use `git add -A`. With that command you rob yourself of the chance to review your own changes before committing them. My experience is, that staging my work file by file, giving at least a fleeting glance at all the diffs avoids quite a number of erroneous commits. Stuff like committing debug code, committing two changes in one commit that should really be two different commits, committing local changes that never should become public, etc. `git add -A .` may be nice and easy to use, but it leads to commits of significantly lower quality. – cmaster - reinstate monica Dec 26 '15 at 20:51

2 Answers2

5

check your .gitignore file there must be some pattern matching this file which is excluding file from being staged. Or you can use git add . -f to forcely add these files.

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
inampaki
  • 159
  • 1
  • 4
  • No, a `.gitignore` only affects files when they're detected as untracked - ie, when they are not yet in the repository. Once a file is in the repository, a `.gitignore` will not apply to it. – Edward Thomson Dec 27 '15 at 02:07
4

It seems like the assume-unchanged-bit is set for that file. With that bit set, git will not look for changes of that file anymore. Unset it by typing:

git update-index --no-assume-unchanged <file>

After that, git status as well as git add should detect the changed file.

functionpointer
  • 1,411
  • 1
  • 13
  • 18