5

Is there a way to have git status ignore certain changes within a file?

Background

I have some files in my repository that are auto-generated (yes, I know that's typically not recommended, but I have no power to change this). Whenever I build my tree, these auto-generated files have status information updated in them (who generated them, a timestamp, etc.).

When I say git status, I'd like it to run a filter on these generated files that strips out this transient status information. I only want it to show up in the "Changed but not updated:" section of git's output if there are other, real changes.

Using the .gitattributes approach found at https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes, I am able to get git diff to ignore these status line changes using a simple egrep filter. I'd like to get git status to also use textconv filters (or something equivalent).

I'd prefer it if merges aren't affected by any of this filtering.

ax.
  • 58,560
  • 8
  • 81
  • 72
Mr Fooz
  • 109,094
  • 6
  • 73
  • 101

3 Answers3

2

You can also use filters to hide your changes from git. Specify "clean" filter that will "clean" unnecessary changes (feed Git's version of file to Git), so it will not see the change (but it still can list the file in "git status").

Details: Better way of making Git to turn a blind eye on my changes

Also see other answers to this question, they also about ignoring changes.

Community
  • 1
  • 1
Vi.
  • 37,014
  • 18
  • 93
  • 148
1

One easy solution is, run the following command on the file or path you want to ignore the changes of:

git update-index --assume-unchanged <file>

If you wanna start tracking changes again run the following command:

git update-index --no-assume-unchanged <file>

you will have to remember to start the tracking again when there is a change that you want to commit.

amitmula
  • 1,060
  • 9
  • 12
  • Thanks for the suggestion; unfortunately, I don't want to completely ignore the files. I just want to ignore certain types of changes within the files. – Mr Fooz Jan 30 '14 at 18:13
0

I thought I'd report back on the two workarounds that I've been using:

  • Remove status information from the auto-generated files.
  • Have an updater script that performs git checkout origin ... as part of the build, for any generated files that had no semantic changes.
Mr Fooz
  • 109,094
  • 6
  • 73
  • 101