0

I need a binary file in repo with tests (it is a mp3 file). The file was committed at first with 644 rights, and I would rather see it as 444.

While git has no problem with detecting file attribute change for text files, it seems to not recognize filemode change for binary.

Given:

tar czf foo.bin /usr/include/*.h
chmod 644 foo.bin
git add foo.bin
git commit -m 'foo headers'

gives effect as expected:

# [master 1509a71] foo headers
#  1 file changed, 0 insertions(+), 0 deletions(-)
#  create mode 100644 foo.bin

But lets change rights to read-only:

chmod 444 foo.bin
git add foo.bin
git commit --amend --no-edit

Then I would expect foo.bin to have proper attributes, but it has not:

# [master 0da87b5] foo headers
# 1 file changed, 0 insertions(+), 0 deletions(-)
# create mode 100644 foo.bin

git --no-pager show --pretty="format:"

# diff --git a/foo.bin b/foo.bin
# new file mode 100644
# index 0000000..08c1e71
# Binary files /dev/null and b/foo.bin differ

this is a brand new repo and git config core.fileMode is set to true, of course.

So my questions are:

Why it is happening?

How can I force git to recognize filemode change?

EDIT:

TL;DR - git tracks only executable bit, see linked answer

m.wasowski
  • 6,329
  • 1
  • 23
  • 30
  • `git commit --amend --no-edit` what's this line for? it give me error when I follow your steps. btw, what's your git version and OS? – number5 Apr 30 '15 at 09:42
  • Ubuntu 14.04.1 LTS, git version 1.9.1. `git commit --amend --no-edit` basically just amends staged files to current commit using the same commit message as before. But if you try go add another commit it fails too: `git commit -m 'foo attr changed'` gives `nothing to commit, working directory clean`. It is clear that git does not recognize filemode change for binary files - and for text files (or an empty file) it works as expected. – m.wasowski Apr 30 '15 at 09:48
  • Very weird. In my case (`git 1.9.0` on Linux), it behaves similarly for text and binary files. However, it does detect that the file has changed if I mess with the `x` bit. But simply with the `w` bit, I see exactly what you see. – Noufal Ibrahim Apr 30 '15 at 09:53
  • tracking binary file mode changes is ok for me with `git version 2.3.7` on OSX 10.9 Mavericks – number5 Apr 30 '15 at 09:54
  • Perhaps a bug in this older version of git then. – Noufal Ibrahim Apr 30 '15 at 09:58

0 Answers0