1000

For some reason, when I initially did a pull from the repository for a git project of mine, I got a ton of files in my working copy that have no discernible changes made to them, but keep showing up in my unstaged changes area.

I'm using Git Gui on Windows xp, and when I go to look at the file to see what has changed. All I see is:

old mode 100755  
new mode 100644  

Does anyone know what this means?

How can I get these files out of my list of unstaged changes? (Very annoying to have to go through 100's of files, just to pick out files I've recently edited and want to commit).

1
  • For the full, gory details on what core.filemode is all about, see my answer here. Note that every Git repository is supposed to have its own core.filemode setting, set by Git at the time Git created that repository; that setting is supposed to be the right one for that one repository. If it's wrong for some reason, you can change it.
    – torek
    Sep 29, 2021 at 16:48

19 Answers 19

1732

That looks like unix file permissions modes to me (755=rwxr-xr-x, 644=rw-r--r--) - the old mode included the +x (executable) flag, the new mode doesn't.

This msysgit issue's replies suggests setting core.filemode to false in order to get rid of the issue:

git config core.filemode false
19
  • 175
    +1. This means that git thinks that it can correctly set the executable bit on checked out files, but when it attempts to do so it doesn't work (or at least not in a way that it can read). When it then reads back the status of those files it looks like the executable bit has been deliberately unset. Setting core.filemode to false tells git to ignore any executable bit changes on the filesystem so it won't view this as a change. If you do need to stage an executable bit change it does mean that you have to manually do git update-index --chmod=(+|-)x <path>.
    – CB Bailey
    Aug 11, 2009 at 6:49
  • 11
    If, like me, the mode changes are important, you can set core.filemode to false, commit your actual code changes, and then set core.filemode to true and git will preserve the file changes. Sep 26, 2009 at 18:48
  • 9
    I have the same problem, but it was due to using the same git repro via SSH git cmd line, and through Git Extensions on a mapped drive in Windows! . . Solution was the same, added into "config" [core] filemode = false Mar 18, 2010 at 9:07
  • 9
    @robsch You can use git config --global ... to set the option in your global config file.
    – Amber
    Mar 3, 2015 at 2:38
  • 4
    You can use git config -l --show-origin to see where each setting is coming from. Nov 12, 2019 at 18:32
126

Setting core.filemode to false does work, but make sure the settings in ~/.gitconfig aren't being overridden by those in .git/config.

To know for sure where the core.filemode setting is coming from, run the following command (works on any OS) from the repository's root folder (or any folder under the root):

git config --show-origin --show-scope --get-all core.filemode

4
  • 3
    Been there, done that. Sadly I found your comment only after having solved the problem myself. Still, +1! Feb 16, 2011 at 15:23
  • 1
    If other users are cloning this project are on Windows, it might be best to actually just apply the change to the ~/.gitconfig file! Dec 13, 2011 at 9:16
  • 1
    If you want to check on Windows Powershell. git config --list --show-origin | sls filemode or on Linux git config --list --show-origin | grep filemode. This will show you where you need to make the adjustments.
    – Frank Fu
    Feb 19, 2019 at 6:31
  • The core.filemode setting is supposed to be set in every .git/config. It is created automatically whenever Git creates a new repository, during git clone or git init, based on how your OS and file system work. It's not supposed to be wrong, but if it is, that's where to fix the setting: in the one specific repository.
    – torek
    Sep 29, 2021 at 16:44
84

This usually happens when the repo is cloned between Windows and Linux/Unix machines.

Just tell git to ignore filemode change. Here are several ways to do so:

  1. Config ONLY for current repo:

     git config core.filemode false
    
  2. Config globally:

     git config --global core.filemode false
    
  3. Add in ~/.gitconfig:

     [core]
          filemode = false
    

Just select one of them.

2
  • 4
    Global config doesn't work because (i guess) git creates a repo with this options set to true (I've created a repo in linux)
    – IC_
    Oct 15, 2019 at 4:47
  • when do these changes need to be applied? Jul 5, 2021 at 11:36
57

I've encountered this problem when copying a git repo with working files from an old hard drive a couple times. The problem stems from the fact that the owner and permissions changed from the old drive/machine to the new one. The long and short of it is, run the following commands to straighten things out (thanks to this superuser answer):

sudo chmod -R -x . # remove the executable bit from all files

The former command will actually resolve the differences that git diff reported, but will revoke your ability to list the directories, so ls ./ fails with ls: .: Permission denied. To fix that:

sudo chmod -R +X . # add the executable bit only for directories

The bad news is that if you do have any files you want to keep executable, such as .sh scripts, you'll need to revert those. You can do that with the following command for each file:

chmod +x ./build.sh # where build.sh is the file you want to make executable again
3
  • 3
    Thanks, helped me a lot! One should also check that git config core.filemode is set to true, otherwise permission changes won't be detected. I also needed to refresh the git index after every change to pick it up.
    – pat-s
    Jan 19, 2018 at 14:56
  • The reason for me having this issue is exactly as described here: I've transferred all my projects to another harddrive when switching to my new computer. Thanks.
    – philburns
    Jan 20, 2022 at 10:16
  • +1, this restores the directories and files to their previous state rather than ignoring the problem as the top answers suggest
    – Nnnes
    Sep 25, 2023 at 3:37
20

I have faced the same issue. And this save my life:

This will revert all the permissions to what the diff is so you are left with nothing, but the changes you made to the files.

https://gist.github.com/jtdp/5443498

git diff -p -R --no-color \
| grep -E "^(diff|(old|new) mode)" --color=never  \
| git apply

More details in https://stackoverflow.com/a/4408378/450383

3
  • 3
    what does it do?
    – Goddard
    Sep 21, 2021 at 11:19
  • This is FANTASTIC! It finds all the files that had their permissions changed and reverts the changing permission without affecting anything else. Thank you! Jun 2, 2022 at 12:38
  • Yes this works like a charm. If there are any files marked as "D" (deleted) you need to deal with them first before applying this solution Aug 25, 2022 at 20:54
12

This worked for me:

git ls-files -m | xargs -L 1 chmod 644
2
  • 1
    Can you please explain what this does? Thanks.
    – philburns
    Jan 20, 2022 at 10:22
  • 1
    This will include deleted files, so will fail as soon as a deleted file is encountered.
    – riley
    May 13, 2022 at 20:03
8

The accepted answer to set git config core.filemode false, works, but with consequences. Setting core.filemode to false tells git to ignore any executable bit changes on the filesystem so it won't view this as a change. If you do need to stage an executable bit change for this repository anytime in the future, you would have to do it manually, or set core.filemode back to true.

A less consequential alternative, if all the modified files should have mode 100755, is to do something like

chmod 100755 $(git ls-files --modified)

which just does exactly the change in mode, no more, no less, without additional implications.

(in my case, it was due to a OneDrive sync with my filesystem on MacOS; by not changing core.filemode, I'm leaving the possibility open that the mode change might happen again in the future; in my case, I'd like to know if it happens again, and changing core.filemode will hide it from me, which I don't want)

0
5

This solution will change the git file permissions from 100755 to 100644 and push changes back to the bitbucket remote repo.

  1. Take a look at your repo's file permissions: git ls-files --stage

  2. If 100755 and you want 100644

    Then run this command: git ls-files --stage | sed 's/\t/ /g' | cut -d' ' -f4 | xargs git update-index --chmod=-x

  3. Now check your repo's file permissions again: git ls-files --stage

  4. Now commit your changes:

    git status
    git commit -m "restored proper file permissions"
    git push
    
3

It seems you have changed some permissions of the directory. I did the following steps to restore it.

$  git diff > backup-diff.txt                ### in case you have some other code changes 

$  git checkout .
3

This happens when you pull and all files were executable in the remote repository. Making them executable again will set everything back to normal again.

chmod +x <yourfile> //For one file
chmod +x folder/* // For files in a folder

You might need to do:

chmod -x <file> // Removes execute bit

instead, for files that was not set as executable and that was changed because of the above operation. There is a better way to do this but this is just a very quick and dirty fix.

1
  • yes but that would create a change that has to be committed later, right? Jul 5, 2021 at 11:23
2

You can use the following command to change your file mode back. git add --chmod=+x -- filename Then commit to the branch.

1

You could try git reset --hard HEAD to reset the repo to the expected default state.

10
  • 9
    If git wasn't able to set the executable bit correctly/consistently after a pull, it's not going to fair any better after a reset.
    – CB Bailey
    Aug 11, 2009 at 6:34
  • 3
    I moved some projects to an usb drive (fat32) and back again to my ubuntu machine (ext4) and ended up with a bunch of changed files, well, the attributes. git reset --hard HEAD worked perfectly for me. thanks Oct 6, 2014 at 3:15
  • 9
    -1. OP states "just to pick out files I've recently edited and want to commit". This would remove those edits too.
    – whitfin
    Oct 6, 2014 at 22:08
  • 12
    -1 Suggesting this command in git is similar to saying "you can just rm -rf ./, I'm sure it won't have any unintended consequences".
    – Kzqai
    Jun 24, 2015 at 20:18
  • 2
    No, this doesn't help and this is the problem. You reset and clean and still git status is showing the mode changes. This is a serious problem with windows git and I think it should be fixed, not just worked around by ignoring the file mode.
    – vezenkov
    Aug 31, 2015 at 12:54
1

This is like what bkm found, but it also takes into account any deleted files and only gives a warning while still applying the changes.

This works well to revert file mode settings from previous commit.

git diff -p --no-ext-diff --no-color --diff-filter=d | grep -E "^(diff|old mode|new mode)" | sed -e "s/^old/NEW/;s/^new/old/;s/^NEW/new/" | git apply
1

A number of the solutions above will break if there are any deleted files.

This will list files that are only modified, and not deleted, and change them all to 755

git diff-files --name-only --diff-filter=d | xargs -L 1 chmod 755
0

I had just the one troublesome file with the changed permissions. To roll it back individually, I just deleted it manually with rm <file> and then did a checkout to pull a fresh copy.

Luckily I had not staged it yet.

If I had I could have run git reset -- <file> before running git checkout -- <file>

0

I just ran into this issue when diffing my branch with master. Git returned one 'mode' error when I expected my branch to be identical to master. I fixed by deleting the file and then merging master in again.

First I ran the diff:

git checkout my-branch
git diff master

This returned:

diff --git a/bin/script.sh b/bin/script.sh
old mode 100755
new mode 100644

I then ran the following to fix:

rm bin/script.sh
git merge -X theirs master

After this, git diff returned no differences between my-branch and master.

2
  • what is theirs? Jul 5, 2021 at 11:25
  • theirs tells the merge to use the version in the other branch (not the current branch, which is referred to as ours). More info on ours vs theirs here. Jul 8, 2021 at 15:19
0

Run git from WSL2 for full Linux compatibility then there is no need for workarounds like flipping core.filemode before and after a commit.

0

Execute this command: chmod 755 xxx replace "xxx" with the path of the file, then hopefully things will go right. The command set the priviledge level back from 100644 to 100755

0

If you're developing in Windows in a linux devcontainer, using the same Windows and WSL version of the folder, you may want to take the following steps:

  1. Unset the filemode in local repo scope (i.e., run this command from within the repo folder hierarchy):

    git config --unset --local core.fileMode

  2. In Windows, set the filemode to false at the global scope (i.e., run from anywhere in Windows):

    git config --global core.filemode false

  3. In the container, set the filemode to true at the global scope (i.e., run from anywhere in the linux container):

    git config --global core.filemode true

Now you won't see the modified files that don't have any file content changes.

Also, you'll may want to make this change in the devcontainer.json file's postCreateCommand option so that it persists when the container is rebuilt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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