29

I have 2 binary files, which have

  • exactly same size
  • exactly same modification date
  • exactly same creation date

but

  • different content

If I replace one file with the other, git does not recognize this file as changed.

Filesystem: NTFS, OS: Windows 7, Git Version: 1.9.0

(my workaround is to edit this new file to get a new modification date but I keep same content)

How can I force Git to commit the new file?

ToBe
  • 921
  • 1
  • 9
  • 23
  • 4
    `touch file.dat; git add file.dat` - basically, force `git` to recognize that the file might be changed so that it acutally checks if it has really been changed... – twalberg Mar 26 '14 at 16:26
  • Thanks, this is fast and will probably also work for SVN. – ToBe Mar 26 '14 at 21:50

2 Answers2

41

You could always do

git rm --cached <file>
git add <file>

This should put the new file into the index regardless of what was previously there.

user3426575
  • 1,723
  • 12
  • 18
  • Thanks, I will accepts this on, althoug this feels more like a workaround than a solution. Comparing this with using touch (proposed by twalberg) I will use touch, because after 'rm' and 'add' , the file is in State **unstracked** , while after 'touch' the file is in State **not staged**. – ToBe Mar 28 '14 at 12:55
  • 1
    Did you actually add the file? It should be **untracked** after `git rm --cached` and **staged** after `git add`. – user3426575 Apr 02 '14 at 18:51
  • Your are right. After git rm --cached : to be deleted After git add : staged for commit **OR** After touch : not staged for commit Depending on what I like to get I will use one of both. – ToBe Apr 03 '14 at 11:33
4

Maybe you accidentally set the “assume unchanged” bit for the file's path.

When the "assume unchanged" bit is on, Git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when you change the working tree file.

To unset the “assume unchanged” bit, type:

git update-index --no-assume-unchanged <file>
user3426575
  • 1,723
  • 12
  • 18
  • I did not set to "assume unchanged". Good Idea, but unfortunatly this does not solve the problem. – ToBe Mar 28 '14 at 12:38