Git status: how to ignore some changes

Is there a way to have git status ignore some changes inside the file?

Background

I have several files in my repository that are automatically generated (yes, I know that it is usually not recommended, but I have no way to change this). Whenever I build my tree, these automatically generated files contain updated status information (who created them, timestamp, etc.).

When I say git status , I would like it to run a filter for these generated files, which removes this transient status information. I want it to appear in the "Changed but not updated:" section of git output if other real changes exist.

Using the .gitattributes approach found at https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes , I can get git diff to ignore these status bar changes using a simple egrep filter. I would like to get git status to use textconv filters (or something similar).

I would prefer that none of these filters affect mergers.

+4
source share
3 answers

It seemed to me that I will talk about two workarounds that I used:

  • Delete status information from automatically generated files.
  • You have a script updater that runs git checkout origin ... as part of the assembly for any generated files that don't have semantic changes.
0
source

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

Read more: The best way to make Git turn a blind eye to my changes

Also see other answers to this question, as well as about ignoring changes.

+1
source

One simple solution is to run the following command in a file or path that you want to ignore changes:

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

If you want to start tracking changes, run the following command:

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

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

+1
source

Source: https://habr.com/ru/post/1307469/


All Articles