1

I have a couple of files in my repository that change every other commit but these changes literally don't change anything. Let me explain. For example, I have a file called ethereal with the following contents:

foo
bar
kappa

I make a commit and then the mysterious entity changes the file to this:

foo, bar,
kappa

These files are exactly the same for the project.

The mysterious entity changes them for no reason. But here's a thing: git doesn't know that these files are the same.

That's why almost every commit includes a meaningless change of the file ethereal.

And no, adding it to .gitignore won't help because ethereal has to be in the project repository.

The commit clutter becomes a real problem.
The only solution I found is typing git update-index --assume-unchanged ethereal before every commit.

But I read here that you are not supposed to do that often. Now imagine that there are 20 files like that.

There's gotta be a better way of dealing with this.

Community
  • 1
  • 1
foxneSs
  • 2,259
  • 3
  • 18
  • 21
  • `--assume-unchanged` sets a bit in the index entry. This bit *remains* set until you clear it or the index entry is removed (or the entire index is removed), so you only need to set it once for each file, in general. But, yes, there may be a better way. – torek Apr 21 '16 at 21:19

1 Answers1

2

The mysterious entity changes them for no reason. But here's a thing: git doesn't know that these files are the same.

Git will see content as changed even if a single byte has been modified.
In your case the files do change in some way, so they are marked as modified.


You can do one of the following:

  1. .gitignore - wont work for you as you described why
  2. --assume-unchanged you already using it.
  3. smudge / clean is here for your rescue

Smudge

Read all about it and to set it up here:
https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes

It turns out that you can write your own filters for doing substitutions in files on commit/checkout.

These are called clean and smudge filters.

In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out (“smudge”, see Figure 8-2) and just before they’re staged (“clean”, see Figure 8-3).

These filters can be set to do all sorts of fun things.

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167