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
- 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.
- 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.
- Add git commit at the end of script.
Save it and run
git custom_script
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…