24

I've created git repository, added code and pushed it to GitHub.

Then locally, I've edited the file Eila.Analyser/Program.cs, that was added to GitHub in first commit, saved it and git status says there's no changes.

Ok, I think, must have messed something up, git reset --hard HEAD, and as I understand that should revert everything, but my file is not reverted.

So I think I'm doing something wrong. I edit file in root folder, git status- shows there are changes, works as suspected, so it works on files in root folder, but not in sub folders.

Am I missing something obvious here?

UPDATE: Evidence, that file I'm editing was really commited (git log --stat):

enter image description here

if it helps, tree picture:

enter image description here

UPDATE2: Ok, I thought I really messed something up, so I've deleted folder, where was my solution, cloned once again from gitHub, and my local code still differs from existing in gitHub and git status sees no changes, git log origin/master..HEAD gives nothing.

Piper
  • 1,266
  • 3
  • 15
  • 26
Giedrius
  • 8,430
  • 6
  • 50
  • 91
  • 2
    Silly question: Program.cs isn't in the .gitignore file is it? – Joe Jan 27 '12 at 14:49
  • no, it is not. Also tried to change another file - app.config, that is in subdirectory also - and it does not work also. – Giedrius Jan 27 '12 at 14:58
  • 2
    @Giedrius are you in a detached head? (http://stackoverflow.com/questions/8213826/egit-branches-local-vs-remote-tracking/8218067#8218067, http://stackoverflow.com/a/1000009/6309)? What does `git branch` returns? – VonC Jan 27 '12 at 15:00
  • `git branch` returns `* master` – Giedrius Jan 27 '12 at 15:09
  • See if your files are actually in your old commits do you see them by doing `git log --stat`? – Joe Jan 27 '12 at 15:24
  • It looks like it is, added screenshot to question of `git log --stat`, also it is visible on github. – Giedrius Jan 27 '12 at 15:30
  • And if modify again a file in a sub-directory, what returns `git status`? Is the any `.git` in said subdirectory (like `Eila.Analyser`)? – VonC Jan 27 '12 at 15:34
  • If edit again, `git status` says nothing to commit, there is no .git in subdirectory. – Giedrius Jan 27 '12 at 15:36
  • 1
    @Giedrius: I understand it says "nothing to commit", but does it says "nothring to add" (or "no changes")? If you don't add to the index, you won't have anything to commit (basic, I know, but just to be extra sure). And what is your git version? You are using msysgit, I suppose? – VonC Jan 27 '12 at 15:43
  • it says nothing to commit (working directory clean). I'm using git bash version, that came with git extensions. – Giedrius Jan 30 '12 at 07:23

10 Answers10

50

Sometimes I have the same problem, especially when I have subfolder which is another git repo itself. The solution is: renaming the folders. Try switching the folder name to something else. Commit that, then rename it back. If the subfolder itself is another Git repo, and you want it to be totally detached from the mainstream, and follow your repo, you should remove the remote of that subfolder first.

21

For me the solution was

Renaming the untracked folder

sqp_125
  • 538
  • 6
  • 21
16

Try running git update-index --really-refresh.

I did have similar problems on Windows and that solves it.

You should also check the core.ignoreStat option with git config.

Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • 1
    didn't worked, git config --get core.ignoreStat returned nothing. – Giedrius Jan 30 '12 at 07:21
  • CAREFUL WITH THIS ONE. I ran it and it undid the changes I had made. However I was then able to make those changes again and they were tracked. – Jason Steele Jul 13 '12 at 08:46
  • @JasonSteele: I don't think that behavior might be caused by `update-index`. Like the name and documentation says, it just updates the index and does not change your working directory. – Koraktor Jul 13 '12 at 20:32
  • I have the same problem where I'm unable to get the latest diff of my code so from this answer I have did `git update-index --really-refresh` which works well for me. Thanks @Koraktor – Anand Jakhaniya Jun 23 '23 at 05:12
11

So finally it worked. I've removed changed files in local folder - then suddenly git status started to see, that those files are missing. So I've restored them and git status started to see, that files are modified.

Giedrius
  • 8,430
  • 6
  • 50
  • 91
6

My case was exactly what Timothy mentioned. I had a subfolder that was also a git repo. I removed the git from the subfolder but the 'parent git' stopped tracking it. Renaming the folder via windows explorer didn't fix the issue but renaming it through git did the job. So, I did '$ git mv folder-name folder-name-temp'.. than renamed back to its original name :)

Valeria Elias
  • 61
  • 1
  • 1
2

For me, the problem was that I had a filename in my .gitignore file which did not exist. Removing this invalid filename from .gitignore solved the problem. Also, I deleted all the .gitignore files from subdirectories and only kept the top-level .gitignore file.

Ashwin
  • 7,277
  • 1
  • 48
  • 70
1

I've tried git update-index --really-refresh and renaming the folder, with no success. This worked though:

  • Duplicate the folder
  • Remove the original
  • Rename the duplicated folder to the original name
Navid
  • 106
  • 2
  • 6
  • This Kind of worked for me. The scenario is that I would make a change and when saved it would not show as if anything was changed, even though I had edited a file. On running the above command the response was; $ git update-index --really-refresh src/databases/Database/dbo/Functions/udfIsRedeemable.sql: needs update and now changes are listed, But it still does not fix the tracking of changes, new changes are not picked up.? – jcrawfor74 Sep 23 '21 at 01:21
1

Did you save the file? when it happened to me, I found out that I had just turned off the "Auto Save" in my editor (VSCode), everything got back to normal when I turned it on again...

  • This was, embarrassingly, what happened to me as well. It was really confusing troubleshooting this, as I haven't manually saved a file in years so it was the last thing I suspected. – Brendan Mar 02 '23 at 18:00
0

PROBELM (In my case)
Performing a git checkout -b <branch_name> had no effect and my folder and files in that branch were still not visible locally, though they are on our gitlab server.

SOLUTION
Copied the SHA hash of last commit in that branch, then locally:

git checkout -b <branch_name> #SHA Hash

Now I see the expected sub-directories and files.

Tony Barganski
  • 1,873
  • 20
  • 17
0

I had the same issue but realised my issue was the ignore at top level. I ignored the .php files so anything that was of .php could not be changed