Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

configuration - Is it possible to configure git to ignore differences in a .frx file if the filesize matches?

I have .FRX files that are binary in nature, and whenever I export code it always shows differences regardless of if changes occurred or not. I would like to automatically determine whether the file needs to be committed based on filesize.

Is there a config file somewhere that would allow this?

question from:https://stackoverflow.com/questions/65602109/is-it-possible-to-configure-git-to-ignore-differences-in-a-frx-file-if-the-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Git uses the SHA-1 of the file contents to keep track of changes. The SHA-1 hash for the directory tree entry is based on the file names (and other meta data) of all files (and subdirectories) in the directory.
If you export code it may change the metadata of files so it shows you changes. You can use a bash script to compare file size changes from last commit to determine if it should be included in the next commit or not. Steps to create a solution

  1. Create a bash script that uses git commands to find out file size of intended files from last commit. You can use git cat-file here.
  2. Compare the size change

a) if it has not changed then check if it already has "skip-worktree" bit set by using

    $ git ls-files -v
    S <file>

The git ls-files -v command will use S to denote files with "skip-worktree" set. If not then, this option in Git can be used to not use working area version with skip-worktree bit.

You can turn it on for a tracked file with

    $ git update-index --skip-worktree <file>

This makes Git use the index version (the last committed version) in place of the version from the filesystem.

b) if it has changed then again use git ls-files -V as mentioned above and if it has "skip-worktree" bit set then use git update-index --no-skip-worktree $file to unset it.

  1. Add git commit at the end of script. Save it and run git custom_script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...