0

I have files that are generated on a regular basis (CSS files from Less). The content is the same but the file is considered different/changed by Git.

It's probably because the date of creation/modification has changed, but I'm wondering how can I avoid committing these files?

I need them on the repository, but I don't want to commit them when the content hasn't changed.

Edit:

Solution found here: Git flag non-modified files as modified when generated by LESS or if line separator has changed

Community
  • 1
  • 1
Vadorequest
  • 16,593
  • 24
  • 118
  • 215
  • Call `git remove ` to untrack a file – msrd0 Nov 09 '14 at 19:20
  • I don't want to untrack it. I need it. – Vadorequest Nov 09 '14 at 19:21
  • 1
    You seem pretty adamant, but you shouldn't need it, and you shouldn't track it. Git isn't for tracking generated content. You should track the source files. Also, Git will not track changes to timestamps. If it's letting you commit it, it's because the contents have changed. Perhaps there is a time-stamp inside the file, in a comment? Look closer at `git diff` and figure out what is actually changing. – user229044 Nov 09 '14 at 19:23
  • The file won't be deleted but untracked so that `git commit -a` won't update the file – msrd0 Nov 09 '14 at 19:23
  • In this specific case I need to track the generated file also. The source isn't good enough. – Vadorequest Nov 09 '14 at 19:37
  • Okay, I close this one then! Thanks. – Vadorequest Nov 10 '14 at 15:27
  • 1
    @msrd0 There is no such Git verb as `remove`... You probably meant `rm`. – jub0bs Nov 10 '14 at 19:47
  • @Jubos Oh sorry you're correct – msrd0 Nov 10 '14 at 20:18
  • I have found an acceptable answer and *it is not* on the "duplicated" topic but on here: http://stackoverflow.com/questions/26931300/git-flag-non-modified-files-as-modified-when-generated-by-less-or-if-line-separa/26931371 I've asked to reopen but it's not useful actually, I've edited the main post, didn't know I could. – Vadorequest Nov 14 '14 at 14:24

1 Answers1

2

... but I don't want to commit them when the content hasn't changed.

You can't. Git tracks content. Git will not allow you to commit a file that has no changes to its content. The premise of your question is incorrect. The file's content has necessarily changed, or you could not commit anything.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Then I guess the content hasn't changed, but maybe the way the file is saved as changed! I'm thinking about the CLRF/CL lines separator. It could be because of this actually! I'll take a closer look. Thanks for hint. – Vadorequest Nov 09 '14 at 19:36
  • It is indeed, due to a change related to line separator. From CLRF to LF when the file is recompiled. – Vadorequest Nov 09 '14 at 19:40
  • https://github.com/less/less.js/issues/1999 LESS compiler always compile in LF, whatever the source line ending is using, that's why. – Vadorequest Nov 09 '14 at 19:49