26

I moved a bunch of my git repositories to another OS by copying to an external hard drive. And now when I do git diff it reports all the files modes have changed.

diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/.npmignore b/.npmignore
old mode 100644
new mode 100755
diff --git a/.travis.yml b/.travis.yml
old mode 100644
new mode 100755
diff --git a/LICENSE b/LICENSE
old mode 100644
new mode 100755
diff --git a/README.md b/README.md
old mode 100644
new mode 100755

I don't really know much about file permissions, what am I supposed to do about this?

Commit the mode changes? Change the mode back for all non-executable files? git reset?

fent
  • 17,861
  • 15
  • 87
  • 91

2 Answers2

52

You can apply this setting

git config core.filemode false

causing git to ignore differences in file-mode.

This solution was found in @kan's answer to another question

Community
  • 1
  • 1
Ross Attrill
  • 2,594
  • 1
  • 22
  • 31
  • 3
    @DeaDEnD this should have been marked as right answer IMO, perhaps worth mentioning in the Q? – Nitsan Wakart Jul 24 '15 at 07:06
  • 1
    Thanks a lot! None of the other suggestions like changing line ending format of files, setting crlf config, hard reset, nothing worked. This worked like a charm. – Nagabhushan S N Aug 28 '21 at 03:40
11

Probably your external hard drive had a different filesystem on it that didn't respect the original file permissions. I'd just correct them by hand before committing.

For example, FAT32, which is commonly used on USB thumb drives, doesn't support execute permissions. When you copy a file from a FAT32 filesystem to a normal Unix-like filesystem, it typically sets execute permission for all files, since that's less damaging than turning it off for all files.

If you want to retain that kind of information, don't copy the files directly to the drive; instead, make a tar file (optionally compressed) and then unpack it on the other end. The tar format does keep track of Unix permission bits.

Note that git itself doesn't keep track of more than executable vs. non-executable. If the mode changes are the only difference, and you don't want to re-copy everything, you can turn the output of git diff into a script does a chmod -x on all the affected files.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • IF that's the case, I'll just re-transfer them some other way. I'm thinking compressing everything into a file. No way I'm correcting all those files by hand. – fent Jan 12 '12 at 22:31
  • Or reformat your external disk with a smarter filesystem. What FS are you going from/to and what's the external disk formatted as? – Carl Norum Jan 12 '12 at 22:32
  • 1
    from/to: ext4, external: ntfs – fent Jan 12 '12 at 23:11
  • 4
    If all files are +x, you can just run `git diff --name-only | xargs chmod -x` to remove the execute bit from all modified files. A more careful & thorough approach would be to use the commands presented in [this answer](http://stackoverflow.com/a/2083563/880767), which handle specifically the mode changes (both +x & -x) – johnny Sep 21 '15 at 18:55