176

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.

8
  • 4
    if you have already committed, then you would have nothing to commit, check git log. Commented Jun 7, 2013 at 21:18
  • 2
    what is the output of git diff ?
    – maazza
    Commented Jun 7, 2013 at 21:18
  • 2
    @maazza I get nothing out of git diff Commented Jun 7, 2013 at 21:21
  • 4
    If git diff (or git status) doesn't show anything that explains why there is nothing to add. So the question is really: "Why doesn't git recognize that my file has been changed?"
    – Sunil D.
    Commented Jun 7, 2013 at 21:25
  • 1
    Sorry guys, I see what is happening.git doesnt see that visual studio C# changed it, but it sees when something else changed it, like notepad++ Commented Jun 7, 2013 at 21:36

38 Answers 38

209

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.

7
  • 45
    git add -f path/to/the/file it will forcefully add the files for commit.
    – San
    Commented Feb 27, 2017 at 9:53
  • 3
    This answer was the only that helped fixing my issue. Not sure if that's a Windows thing (I have never had any problems like this in the past, either in osx or linux). So thanks to @ThorSummoner. Btw, I tried git add -f the file that was in this "assume unchanged" state, and it did not work - had to either git update-index or git rm --cached followed by a git reset to make it work.
    – rsenna
    Commented Aug 8, 2017 at 15:33
  • 13
    Also, if you are really unsure about your repo current state, do this: git rm --cached -r . and then git reset ..
    – rsenna
    Commented Aug 8, 2017 at 15:38
  • 1
    Worked for me, but yes only single file cases. Commented Aug 18, 2018 at 19:47
  • 2
    It works, with this command as per @rsenna git rm --cached -r . and then git reset . Commented Jul 7, 2021 at 6:36
41

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.

9
  • 7
    Damn. I thought: How stupid. That can't really ever be an issue... until I check my editor's path. 😖
    – Riquochet
    Commented Mar 3, 2021 at 1:35
  • 1
    Haha yea this happened to me, it was due to an unused dupe directory I made during project creation and forgot to get rid of it. I spent roughly 1-2 hours trying to solve this issue... Turns out it was just that. Thanks man Commented Apr 13, 2022 at 3:41
  • Or how about having two similar files in the repo with one being ignored? PEBCAK
    – rhs
    Commented Jul 15, 2022 at 10:04
  • only discovered when clicked with right button 'reveal in file explorer' to see that I was in different files with same name! Commented Oct 26, 2022 at 20:48
  • I was updating the compiled .css file (git ignored) instead of uncompiled .scss
    – Mike
    Commented Mar 15, 2023 at 16:08
33

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.

4
  • 1
    I've used gitignore.io to generate my .gitignore and I've found a line with lib/, what makes git ignore this folder. There is no problem with that - at least if this folder is not the main folder from your project, like what happened to me.
    – Paladini
    Commented May 13, 2017 at 22:18
  • 1
    And for anyone in my case, it was actually my global excludesfile Commented May 15, 2017 at 1:52
  • At first, this did not work. But, I got it to work. In my case, the thing to be ignored was mentioned twice in the gitignore file. Always search for all occurrences and replace all.
    – MasterJoe
    Commented Aug 1, 2018 at 19:18
  • @vpzomtrrfrt my problem was exactly that, the excludefile, don't know how it got there ! Commented Jun 13, 2023 at 11:20
16

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.

2
  • 2
    For me git status says no files are changed, but git add . adds two files, and git update-index --really-refresh says those two need updates, but doesn't seem to do anything. Any idea? Commented May 23, 2019 at 10:34
  • 2
    git status ignores files with assume-unchanged flag. However using git update-index --really-refresh will clear that flag and the files will now show up. Try running git status again to see if it now changes the changes. If you dont see anything follow this post: stackoverflow.com/questions/2363197/… most notably the command to display a listing of files that have the assume-nochanges: git ls-files -v | grep '^[[:lower:]]' If nothing helps you should create a question with more details so we can help you. Commented May 23, 2019 at 13:25
16

Following commands worked for me

rm .git/index

git reset
3
  • 2
    This worked for me. Would love to know, where you come across this and why it is happening?
    – Aswin
    Commented Oct 23, 2022 at 17:43
  • I found that git reset is used to remove all staged changes. That being said, you don't need to run git reset after deleting the index because deleting the index already removes staged changes
    – bocodes
    Commented Nov 2, 2023 at 20:37
  • "X worked for me" answers, with no explanation, are very low quality answers. Lazy and dangerous. Commented Mar 25 at 11:06
9

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.

3
  • 1) no stash found 2) I had changes and committed, so can i commit again? 3) I didn't do that 4) I am in the right repo Commented Jun 7, 2013 at 21:31
  • if you had changes and committed them, then you are good go to the next step, push or whatever your workflow is... You can commit again if you have more changes, you can even git commit --amend which will put your new changes in your last commit, don't do that if you have already shared your commit though. Commented Jun 7, 2013 at 21:37
  • Closing and reopening the terminal did it for me after cleaning a project repo.
    – Eddie
    Commented Nov 27, 2019 at 6:30
7

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.

1
  • Exactly my problem. This is some weird edge case specific to submodules I think. Anyways, I did this then git restore --staged * and suddenly my changes were tracked.
    – Chris Wong
    Commented Nov 23, 2022 at 1:18
6

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.

5

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.

1
  • Any idea how this issue can be fixed when it happens in intellij ?
    – MasterJoe
    Commented Jul 5, 2018 at 6:03
4

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.

3
  • Have you figured out a solution for this? I've been fighting with my git not recognising my changed files when I use any merging tool, and the only way to get git to see the changes is by using nano for my merges, which takes much more time. The conflicted files are initially visible to git, its after they're edited by the merge tool they are showing up as "unchanged" on git.
    – Lucas P.
    Commented Mar 27, 2020 at 14:15
  • i dont know why this works and how this works but it works for me thanks
    – Amit Bisht
    Commented Apr 8, 2020 at 6:30
  • This is the only thing that works, which is a right pain
    – Chris Pink
    Commented Apr 6, 2022 at 8:17
3

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!

3

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 -
2
  • Wow, this was the case. Crazy. Another tricks didn't work at all!
    – Makalele
    Commented Jun 18, 2020 at 14:10
  • lol. this was the main issue in my case. Didn't even see the current path. Thanks for mentioning it!
    – rufatZZ
    Commented Nov 14, 2022 at 10:49
3

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.

1
  • This is happening to me too
    – Kloar
    Commented Aug 16, 2018 at 12:59
3

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

3

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>
3

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

3

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.

2
  • This worked for me when adding comments to a .js file, working with Visual Studio Code. Thank you.
    – SnuKies
    Commented Jul 11, 2019 at 12:47
  • Nice, simply pressing CTRL + S while having the file open in VS Code worked for me. Thank you.
    – Hannah
    Commented Mar 27, 2022 at 21:13
2
git update-index --really-refresh

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

2

I had the same problem after Google Drive desktop synced my project files, Git was not detecting changes.

What I found is that this git rm --cached -r . with sudo credentials work. Then don't do git reset, this only resets git status and set everything back to the point in time of the issue.

So for Linux and mac, this works well:

`sudo git rm --cached -r .`
2

If you are using VSCode you have to save the changes first before git can recognize them.

Press:

Ctrl + Shift + S for Window

Command + S for Mac

now git status again

1

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).

1
  • thank you for mentioning this! I was so convinced I was updating the right file. Nope. face palm Commented Mar 13, 2019 at 20:55
1

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.

1

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.

1

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

1

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.

1

Check your excludefile in the .git folder. I had the same issue and got some entry in the excludefile (or excludesfile) that prevented git to work correctly

0

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.

0

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.

0

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.

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.