Editing
Troubleshooting of GIT
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Git Shows Files as Modified After chmod — File Mode Changes === '''Problem''' After running <code>chmod +x</code> or copying the repository between different operating systems or file systems, Git may report files as modified even though their contents have not changed: <pre> git status modified: scripts/deploy.sh </pre> Running <code>git diff</code> may show only a file mode change: <pre> diff --git a/scripts/deploy.sh b/scripts/deploy.sh old mode 100644 new mode 100755 </pre> In Git file modes: * <code>100644</code> means a regular non-executable file. * <code>100755</code> means a regular executable file. Git records the executable bit as part of the tracked file metadata. Therefore, adding or removing executable permission can appear as a modification even when the file contents are identical. Git’s diff format explicitly reports these changes as <code>old mode</code> and <code>new mode</code>. '''Diagnosis''' Use the following command to check whether the reported changes are file mode changes only: <pre> git diff --summary </pre> Example output: <pre> mode change 100644 => 100755 scripts/deploy.sh </pre> You can also inspect the full diff: <pre> git diff </pre> If the output contains only <code>old mode</code> and <code>new mode</code>, without added or removed content lines, the change is caused by the executable bit rather than file contents. Check the current repository setting with: <ref>[https://git-scm.com/docs/git-config?utm_source=chatgpt.com Git - git-config Documentation]</ref> <pre> git config --get core.fileMode </pre> To see which configuration file defines the value: <pre> git config --show-origin --get core.fileMode </pre> '''Cause''' The behavior is controlled by Git’s <code>core.fileMode</code> setting. When it is set to <code>true</code>, Git checks whether the executable bit in the working tree differs from the mode stored in the Git index. This can create unexpected changes when: * A file was modified using <code>chmod +x</code> or <code>chmod -x</code>. * A repository was copied between Linux, macOS, Windows, a network drive, or another file system with different permission behavior. * An archive, synchronization tool, or shared folder changed executable permissions. * A container or deployment process rewrote file modes. Git’s documentation notes that some file systems may not reliably preserve executable-bit information, which is why <code>core.fileMode</code> can be disabled when those mode differences should not be trusted. '''Solution''' To ignore executable-permission changes in the current repository, run: <pre> git config core.fileMode false </pre> This is the recommended scope when the issue affects only one repository. The setting is saved in that repository’s <code>.git/config</code> file. To apply the setting to all repositories for the current user: <pre> git config --global core.fileMode false </pre> The global setting is stored in the user-level Git configuration and acts as a fallback unless a repository overrides it. Verify the effective value: <pre> git config --get core.fileMode </pre> The expected output is: <pre> false </pre> Then check the repository again: <pre> git status git diff --summary </pre> Permission-only changes should no longer appear as unstaged modifications. '''Restore File Mode Tracking''' To restore executable-bit tracking for the current repository: <pre> git config core.fileMode true </pre> To remove the repository-specific override and return to the global or system default: <pre> git config --unset core.fileMode </pre> To restore tracking globally: <pre> git config --global core.fileMode true </pre> '''When the Executable Bit Should Be Committed''' Do not disable <code>core.fileMode</code> merely to hide a legitimate permission change. For shell scripts, deployment scripts, Git hooks, command-line tools, and other files that must be executable after checkout, record the executable bit in Git intentionally: <pre> chmod +x scripts/deploy.sh git add scripts/deploy.sh git commit -m "Mark deploy script as executable" </pre> The committed mode change will appear as: <pre> mode change 100644 => 100755 scripts/deploy.sh </pre> If the local file system cannot apply <code>chmod</code> correctly, update the Git index directly: <pre> git update-index --chmod=+x scripts/deploy.sh git commit -m "Mark deploy script as executable" </pre> To remove executable status from the Git index: <pre> git update-index --chmod=-x scripts/deploy.sh </pre> Git provides index-level support for explicitly overriding a tracked file’s executable bit. {{exclaim}} Notice: Setting <code>core.fileMode=false</code> does not change the actual operating-system permissions and does not rewrite previously committed file modes. It only tells Git not to treat executable-bit differences in the working tree as modifications. Use a repository-level setting unless the same problem consistently affects all repositories on the machine.
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information