Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff reporting mode changes after moving the repository

Tags:

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?

like image 852
fent Avatar asked Jan 12 '12 22:01

fent


People also ask

Why is git diff not showing anything?

There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.

How does git diff change if you add the -- color words option to the command?

git diff --color-words git diff also has a special mode for highlighting changes with much better granularity: ‐‐color-words . This mode tokenizes added and removed lines by whitespace and then diffs those. Now the output displays only the color-coded words that have changed.

How does git diff work internally?

Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.


Video Answer


2 Answers

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

like image 146
Ross Attrill Avatar answered Sep 22 '22 04:09

Ross Attrill


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.

like image 41
Carl Norum Avatar answered Sep 20 '22 04:09

Carl Norum