Git adding "unchanged" files to the stage
Asked Answered
A

2

13

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?

Animus answered 3/9, 2013 at 20:9 Comment(8)
By any chance, is the file gitignored. See if there's a .gitignore file and an entry in there, for this file.Hollywood
No, the filetype is not in my .gitignore.Animus
There's an old SO question : #9708062. Have you tried these?Hollywood
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.Animus
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.Hollywood
In fact, try deleting a file and adding the same file again. Git will think no changes!Hollywood
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.Fabliau
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.Litha
L
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.

Lyndsaylyndsey answered 26/12, 2015 at 20:13 Comment(1)
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.Sungsungari
C
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.

Crackbrain answered 9/9, 2013 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.