How do I make Git ignore file mode (chmod) changes?

To make Git ignore file mode (permission) changes (e.g., chmod modifications), you can configure Git to disregard executable bit changes. Here’s how to do it:

Step 1: Configure Git to Ignore File Mode Changes

Set the core.fileMode setting to false in your Git configuration.

For a Single Repository (Local Config):

git config core.fileMode false

For All Repositories (Global Config):

git config --global core.fileMode false

Step 2: Verify the Setting

Check if the setting is applied correctly:

git config --get core.fileMode
# Output: false (if set correctly)

How It Works

  • When core.fileMode is false, Git will ignore changes to file permissions (e.g., 755644).
  • This setting does not affect existing tracked files until their content changes. To refresh the index for existing files, run:
  git reset --hard HEAD

Example Workflow

  1. Before Configuration:
   chmod +x script.sh    # Make a file executable
   git status            # Shows "modified: script.sh"
  1. After Configuration:
   git config core.fileMode false
   chmod +x script.sh    # Permission change
   git status            # No changes detected

Notes

  • Windows Users: Git for Windows automatically sets core.fileMode to false because file modes are not natively tracked.
  • Unix/Linux/macOS: core.fileMode is true by default.
  • Exception: To stage a permission change for a specific file, temporarily re-enable core.fileMode:
  git -c core.fileMode=true add script.sh

Troubleshooting

If files still show mode changes after configuration:

  1. Refresh the Git Index:
   git update-index --really-refresh
  1. Check for Overrides:
    Ensure no other Git config files (e.g., .git/config or ~/.gitconfig) override the setting.

By disabling core.fileMode, you ensure Git focuses on content changes, not permissions.

Leave a Reply

Your email address will not be published. Required fields are marked *