3

I have a case where file I modify does not appear as modified file.

Can i still commit that file?

Can I add file that is listed as unchanged file to changed file? Thanks!

Updates: When I'm trying to add the file, terminal gives such error:

The following paths are ignored by one of your .gitignore files:
folderpath/filename.java
Use -f if you really want to add them.
fatal: no files added

but when I open my .gitignore file:

bin
gen
#built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated GUI files
*R.java

# Mac OS file
.DS_Store

and info/exclude

# 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]
# *~

I am very sure my folder path and its file name is not included in .gitignore and exclude file

Rendy
  • 5,572
  • 15
  • 52
  • 95
  • hi eckes..i've tried your answer on other post: - the folder is added - my file is not in .gitignore and exclude list - when i try to type git config --global core.excludesfile, terminal doesn't print anything... - git status --ignored shows all my changes to be committed list (sounds strange right?) – Rendy Aug 03 '12 at 09:11
  • yes, my folder for that file is not within bin/gen :) – Rendy Aug 03 '12 at 09:20
  • Thanks for your explanation! I never know such rule.. No, my folder path name doesn't contain gen or bin – Rendy Aug 03 '12 at 09:26
  • could you **please** post the full path and the full filename? This will help us figuring out the problem! – eckes Aug 04 '12 at 12:27
  • hi eckes..i'm sorry but i can't reveal the full path as it is credential :( – Rendy Aug 07 '12 at 02:14
  • you might rethink your project structure if the file **names** reveal secrets. and if it helps, it is not necessary to reveal the *full* path of your file, only the path relative to your project (where .git/ lives) – umläute Aug 21 '12 at 07:42

4 Answers4

2

git will not track changes in untracked files.

so first make sure that your file is actually tracked by git. others have written at length on why you file might be ingored (.gitignore, .git/info/exclude,...)

then make sure that your file really contains changes (seems to be obvious). what kind of changes did you do to the file? note that you can configure git to ignore changes to the EOL, so modifying a file by changing CRLF to LF does not qualify as a "change to be committed". check this.

Community
  • 1
  • 1
umläute
  • 28,885
  • 9
  • 68
  • 122
  • please see my edited post.. i've added some lines of code in that file, not a simple character or EOL.. – Rendy Aug 03 '12 at 08:42
1

Please check: maybe your modified file matches a pattern in .gitignore file in your repository root. If this happends, the files becomes 'out of the scope' for git.

umläute
  • 28,885
  • 9
  • 68
  • 122
shytikov
  • 9,155
  • 8
  • 56
  • 103
  • But if which folder that file is situated? Maybe it was ignored due to folder restriction? Could you please give full name of the file and folder so we can understand the issue more clearly? I believe this is not huge secret? – shytikov Aug 03 '12 at 07:13
  • Thanks for your comment, but when I try to modify other file in that folder, git can detect my modified file as modified. It sounds strange right? – Rendy Aug 03 '12 at 07:24
  • Yes... but what about this line `*R.java` maybe your file name matches it? If you're on Windows it probably ignores case and... score! I would suggest to disable statements in `.gitignore` one by one, run `git status` and see what's happening. This is "monkey's approach" but it's more efficient than guessing. – shytikov Aug 03 '12 at 07:28
  • R.java is an auto-generated file by Eclipse..Looking from .gitignore content, my file isn't included..I think I'll just add the file using -f as eckes suggested.. – Rendy Aug 03 '12 at 07:32
  • `-f` is nice solution, but it does not reveals the source of the issue. – shytikov Aug 03 '12 at 07:48
  • 2
    did you check `.git/info/exclude` as well? – J-16 SDiZ Aug 03 '12 at 08:36
  • AlexeyShytikov: yes i know, i'm still curious too... @J-16SDiZ please see my edited post.. – Rendy Aug 03 '12 at 08:41
  • How about global `gitignore`? In the `~/.gitignore_global` file? – shytikov Aug 03 '12 at 08:42
  • i'll research more later on gitignore_global..will post here later if there is a good result – Rendy Aug 03 '12 at 09:19
1

Your posted .gitignore does not indicate that the file is ignored from that one but there's not only your .gitignore present on the working copy that defines files to be ignored.

See this answer for an overview of files and circumstances that are relevant for ignoring things.

Nonetheless, the message you get from git is quite clear: if you don't want to find why the file is ignored, Use -f if you really want to add them.


Edit:
If you're absolutely sure that you checked all your .gitignores, take a careful look at the patterns in .gitignore. For example, your .gitignore contains the pattern gen. If your changed file is found at mygenerator/myfile.java, the gen pattern will match mygenerator and will ignore the changes...

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201
1

I'm checking the initial source for your .gitignore: https://github.com/github/gitignore/blob/master/Android.gitignore

And one thought pops out in my head: you're using following pattern:

bin
gen

while they are using

# generated files
bin/
gen/

The difference is insignificant — the / but instead of matching only folders your rule may match files as well.

shytikov
  • 9,155
  • 8
  • 56
  • 103
  • 2
    @Rendy, could you please reveal the name of the file? Because it's hard to search for the answer — we need to know to which pattern it become matched. – shytikov Aug 03 '12 at 09:30
  • 1
    hi alexey, thanks for your help but i can't reveal its path since it's credential :( – Rendy Aug 07 '12 at 02:15
  • Ok, but are you sure, that `bin` and `gen` chunks could not be found in the name of the file? I bet they are! – shytikov Aug 07 '12 at 05:40