Why doesn't git recognize that my file has been changed, therefore git add not working

GitGithub

Git Problem Overview


I am trying to push my files to github using bash. They are already on there, and I am uploading a newer version with new lines and code, etc. But when I try git add and then git status it says:

> On branch master > > nothing to commit, working directory clean

And the file I am using was just modified.

Git Solutions


Solution 1 - Git

I had a problem where once upon a time I set the git index to 'assume unchanged' on my file.

You can tell git to stop ignoring changes to the file with:

git update-index --no-assume-unchanged path/to/file

If that doesn't help a reset may be enough for other weird cases.


In practice I found removing the cached file and resetting it to work:

git rm --cached path/to/file
git reset path/to/file

The git rm --cached means to only remove the file from the index, and reset tells git to reload the git index from the last commit.

Solution 2 - Git

Check your .gitignore file. You may find that the file, or extension of the file, or path to the file you are trying to work with matches an entry in .gitignore, which would explain why that file is being ignored (and not recognized as a changed file).

This turned out to be the case for me when I had a similar problem.

Solution 3 - Git

Sounds crazy, but sometimes you are not in the right repo even though you think you are. For example, you may have moved the parent directory, but forgot to switch repos in your text editor. Or vice versa: you're in the right repo in the text editor but the wrong repo in command line. In the first situation, you make your edits in the right file but it's not the same folder that's open in your command line, so it's actually the wrong file. In the second situation, you actually did edit the right file, but your command line git won't recognize the change because you're not in the correct directory on the command line.

Solution 4 - Git

Like it was already discussed, the files were probably flagged with "assume-unchanged", which basicly tells git that you will not modify the files, so it doesnt need to track changes with them. However this may be affecting multiple files, and if its a large workspace you might not want to check them all one by one. In that case you can try: git update-index --really-refresh

according to the docs:

Like --refresh, but checks stat information unconditionally, without regard to the "assume unchanged" setting.

It will basicly force git to track changes of all files regardless of the "assume-unchanged" flags.

Solution 5 - Git

well we don't have enough to answer this question so I will give you several guesses:

  1. you stashed your changes, to fix type: git stash pop

  2. you had changes and you committed them, you should be able to see your commit in git log

  3. you had changes did some sort of git reset --hard or other, your changes may be there in the reflog, type git reflog --all followed by checking out or cherry-picking the ref if you ever do find it.

  4. you have checked out the same repo several times, and you are in the wrong one.

Solution 6 - Git

I had some git submodule misconfiguration. I went to repo's root and issued these commands on the directories that had .git folders previously:

git rm --cached sub/directory/path -f

Then the directories appeared in git status.

You may want to make a copy of your repo before trying this just in case.

Solution 7 - Git

Had a funky thing like this happening. Eclipse Kepler's git plugin was automatically marking all my project folders as ignored in the .gitignore folder.

When I would got to commit on the Team menu, they would all set back to ignored. As far as I can tell, this was because I'd set them as derived in the parent project. Unmarking them as dervied fixed this. I'd never seen this before on Indigo. Hope it helps someon.

Solution 8 - Git

We've had this happen on Windows when changing files by transferring differences via the WinMerge tool. Apparently WinMerge (at least the way it's configured on my computer) sometimes doesn't update the timestamps of files it changes.

On Windows, git status, uses, among other things, a file's time stamp and changes in the file's size to determine whether or not a file has changed. So since the time stamp wasn't updated, it only had the file size to go by. Unfortunately the file in question was a simple version file where the content changed from 7.1.2 to 7.2.0. In other words, the file size also remained unchanged. Other files that were also changed by WinMerge and didn't have their time stamps updated but had a different size after the change were detected by git status just fine.

Solution 9 - Git

TL;DR; Are you even on the correct repository?

My story is bit funny but I thought it can happen with someone who might be having a similar scenario so sharing it here.

Actually on my machine, I had two separate git repositories repo1 and repo2 configured in the same root directory named source. These two repositories are essentially the repositories of two products I work off and on in my company. Now the thing is that as a standard guideline, the directory structure of source code of all the products is exactly the same in my company.

So without realizing I modified an exactly same named file in repo2 which I was supposed to change in repo1. So, I just kept running command git status on repo1 and it kept giving the same message

> On branch master > > nothing to commit, working directory clean

for half an hour. Then colleague of mine observed it as independent pair of eyes and brought this thing to my notice that I was in wrong but very similar looking repository. The moment I switched to repo1 Git started noticing the changed files.

Not so common case. But you never know!

Solution 10 - Git

I had a similar issue while using Sublime Text-3. After making new changes in the code and saving it, when I tried the git add ./status commands the response was "branch already-up to date". I figured out, regardless saving the updates in the text editor, the file was actually unchanged. Opening file in other editor and saving the changes worked for me.

Solution 11 - Git

When you edit a file in Visual Studio it gets listed in git changes instantly even if the file is not saved. So all you need to do is just to save the file manually (Ctrl+S for the currently displayed file or Ctrl+Shift+S for all project files) and git bash will pick them up.

Solution 12 - Git

Did you move the directory out from under your shell? This can happen if you restored your project from a backup. To fix this, just cd out and back in:

cd ../
cd -

Solution 13 - Git

It happend to me as well, I tried the above mentioned methods and nothing helped. Then the solution was to change the file via terminal, not GUI. I do not know why this worked but worked. After I edited the file via nano from terminal git recognized it as changed and i was able to add it and commit.

Solution 14 - Git

I had the same issue. And the files that I needed to be committed were never declared in the .gitignore file as well.

In my case adding the files forcefully using the -f flag elevated to staging and fixed the issue.

git add -f <path to file>

Solution 15 - Git

git update-index --really-refresh

you can try this command, it will update indexes in your folder.

Solution 16 - Git

Following commands worked for me

rm .git/index

git reset

Solution 17 - Git

In general with this issue, first check that you're editing the file you think you are! I had this problem when I was editing a transpiled JavaScript file instead of the source file (the transpiled version wasn't under source control).

Solution 18 - Git

My Git client (Gitg) caused this issue for me. Normal commands that I would usually run weren't working. Even touching every file in the project didn't work.

I found a way to fix it and I'm still not sure what caused it. Copy your project directory. The missing files will show up in the copied directory's git status. Renaming might do the same thing.

Solution 19 - Git

Make sure not to create symlinks (ln -s source dest) from inside of Git Bash for Windows.

It does NOT make symlinks, but does a DEEP copy of the source to the dest

I experienced same behavior as OP on a MINGW64 terminal from Git Bash for Windows (version 2.16.2) to realize that my 'edited' changes actually were in the original directory, and my git bash commands were from within a deep copy that had remained unchanged.

Solution 20 - Git

I had the same problem. Turns out I had two copies of the project and my terminal was in the wrong project folder!

Solution 21 - Git

Ran into the issue, but it was only two directories and unknown to me was that both those directories ended up being configured as git submodules. How that happened I have no clue, but the process was to follow some of the instructions on this link, but NOT remove the directory (as he does at the end) but rather do git add path/to/dir

Solution 22 - Git

What kind of file do you tried to upload? Now I just spend almost an hour to upload my css modification. But this css compiled from a styl file therefore git just ignored it. When I changed the styl source then everything worked.

Hope it helps.

Solution 23 - Git

Sometimes depend and by git version and if you forget to do git add ..

To check about your change on repository use always git status that show all untracked and changed files. Because git diff show only added files.

Solution 24 - Git

i have the same problem here VS2015 didn't recognize my js files changes, removing remotes from repository settings and then re-adding the remote URL path solved my problem.

Solution 25 - Git

I had a similar issue when I created a patch file in server with vi editor. It seems the issue was with spacing. When I pushed the patch from local, deployment was proper.

Solution 26 - Git

If you are using VSCode and switched to a new machine, you may have Autosave off, so even if you make changes to a file, git won't recognize them.

This solved my issue

Solution 27 - Git

The following worked for me:

git mv tesfile.js TestFile.js

for more details check out: https://stackoverflow.com/a/16071375/11677643

Solution 28 - Git

This happened to me when all changes were in a new directory. I added the first file

git add newdirectory/new.file

and then git status showed the other files in the directory as expected.

Solution 29 - Git

Try renaming the File and git will recognize a new change to add the file.

For example , if the File path is Product/index.tsx then you can just rename the path to : ProductItem/index.tsx.

This worked! after attempting all the suggested solutions above.

Solution 30 - Git

I had this issue. Mine wasn't working because I was putting my files in the .git folder inside my project.

Solution 31 - Git

try to use git add * then git commit

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsomerandomguyView Question on Stackoverflow
Solution 1 - GitThorSummonerView Answer on Stackoverflow
Solution 2 - GitMarc Eliot SteinView Answer on Stackoverflow
Solution 3 - GitMonroe MannView Answer on Stackoverflow
Solution 4 - GitAndré CunhaView Answer on Stackoverflow
Solution 5 - GitGrady PlayerView Answer on Stackoverflow
Solution 6 - GitpmaguniaView Answer on Stackoverflow
Solution 7 - GitJoseph LustView Answer on Stackoverflow
Solution 8 - GitantredView Answer on Stackoverflow
Solution 9 - GitRBTView Answer on Stackoverflow
Solution 10 - GitBalraj GillView Answer on Stackoverflow
Solution 11 - GityaugenkaView Answer on Stackoverflow
Solution 12 - GitSilverWolfView Answer on Stackoverflow
Solution 13 - GitZed895View Answer on Stackoverflow
Solution 14 - GitInsightcoderView Answer on Stackoverflow
Solution 15 - GitKehe CAIView Answer on Stackoverflow
Solution 16 - GitganeshView Answer on Stackoverflow
Solution 17 - GitChris HalcrowView Answer on Stackoverflow
Solution 18 - GitkagronickView Answer on Stackoverflow
Solution 19 - GitStevenWernerCSView Answer on Stackoverflow
Solution 20 - GitzarView Answer on Stackoverflow
Solution 21 - GitAndrew LankView Answer on Stackoverflow
Solution 22 - GitPaxiView Answer on Stackoverflow
Solution 23 - GitonalbiView Answer on Stackoverflow
Solution 24 - GitMuzafar HasanView Answer on Stackoverflow
Solution 25 - GitPkrishnaView Answer on Stackoverflow
Solution 26 - GitShile WenView Answer on Stackoverflow
Solution 27 - GitTeodor CrnobrnjaView Answer on Stackoverflow
Solution 28 - GitrobmView Answer on Stackoverflow
Solution 29 - Gitxolani maphumuloView Answer on Stackoverflow
Solution 30 - GitLafsnbView Answer on Stackoverflow
Solution 31 - GitTih HaurView Answer on Stackoverflow