PricingSign inDownload

Blog / git

git shows mode 100644 to 100755 after an agent? Undo just that

An agent made files executable and git lists them as changed with no edits. Find them, undo just the mode, keep real edits, set a script executable.

On this page
  1. Why it happens
  2. List the files whose mode changed
  3. Undo the mode, keep the edits
  4. The agent already committed it
  5. A script that should be executable
  6. Turning mode tracking off
  7. Catch it before the commit
  8. Ask the agent not to
  9. Frequently asked questions
  10. What does "old mode 100644 new mode 100755" mean in git?
  11. How do I undo file mode changes in git but keep my edits?
  12. Should I set core.fileMode to false?
  13. How do I make a file executable in git on Windows?
  14. Try it with your team

After an agent run, git status lists files you never asked it to touch. The diff has no lines in it, just this:

diff --git a/a.txt b/a.txt
old mode 100644
new mode 100755

The file's contents are the same; the agent made it executable. It's usually a chmod +x on a whole folder to get one script to run, or a tool that copied files with the wrong permissions. Git tracks the executable bit, so each one is a change. We tested the fixes below with git 2.43.

Why it happens#

The usual causes: the agent tried to run a script, got "permission denied", and fixed it with chmod -R +x on the folder instead of the one file; it unpacked or copied files from somewhere that marks everything executable; or it rewrote a file with a tool that didn't keep the original mode. None of these changes what the files do, but each one lands in your diff.

List the files whose mode changed#

bash
git diff --summary
 mode change 100644 => 100755 a.txt
 mode change 100644 => 100755 b.txt
 mode change 100644 => 100755 build.sh

git diff --stat shows them too, with 0 lines changed:

 a.txt    | 0
 b.txt    | 0

A file with both a mode change and an edit shows up in both lists, with its line count in --stat.

Undo the mode, keep the edits#

Remove the executable bit from every file that gained one:

bash
git diff --summary | awk '/mode change 100644 => 100755/ {print $NF}' | xargs chmod -x

In our test b.txt had a real edit as well as the mode change. After the line above it still showed as modified, with only the edit:

 b.txt | 1 +

The awk takes the last word, so it breaks on file names with spaces; check git diff --summary again after it.

For a file with no edits at all, git restore a.txt puts back both the mode and the contents. Don't use it on a file that has edits you want: it undoes those too.

The agent already committed it#

If the mode change is already in the agent's commits, look at the whole branch, not just your folder:

bash
git diff --summary main...HEAD
 mode change 100644 => 100755 a.txt

To find which commit did it, git log --summary lists mode changes per commit:

bash
git log --summary --format='%h %s' main..HEAD | grep -B2 "mode change"
73eca95 agent: stuff

 mode change 100644 => 100755 a.txt

Fix it with one more commit on the branch:

bash
chmod -x a.txt
git commit -am "a.txt is not executable"
git diff --summary main...HEAD

The last command printed nothing: compared with main, the branch no longer changes the mode. If the branch isn't shared yet, you can fold the fix into the agent's commit instead, but a new commit is always safe.

A script that should be executable#

If the agent made a new script executable and it should be, commit the mode with it. git add picks the mode up from the file:

bash
chmod +x build.sh
git add build.sh

On Windows, or with core.fileMode off, the file system doesn't carry the bit, so set it in git directly:

bash
git update-index --chmod=+x build.sh
git ls-files -s build.sh
100755 8b2fe5434fec16870a71cd8b272c7fcf6d352536 0	build.sh

100755 is executable, 100644 isn't.

Turning mode tracking off#

bash
git config core.fileMode false

With that set, our three files dropped out of git status. It's a setting for your copy of the repo, not the project, so teammates and their agents still see mode changes you commit. It also means a script you make executable on purpose isn't picked up any more: use git update-index --chmod=+x for those. It suits a folder on a drive that can't store the bit properly; on a normal Mac or Linux folder, it's better to fix the files.

Catch it before the commit#

A git hook can refuse any commit that changes a file's mode, so the agent sees the problem at the moment it commits. Save this as .git/hooks/pre-commit and make it executable:

bash
#!/bin/sh
if git diff --cached --summary | grep -q "mode change"; then
  echo "This commit changes file modes:" >&2
  git diff --cached --summary | grep "mode change" >&2
  echo "Undo them with chmod, or commit with --no-verify if you meant it." >&2
  exit 1
fi

With b.txt made executable, the commit stopped:

This commit changes file modes:
 mode change 100644 => 100755 b.txt
Undo them with chmod, or commit with --no-verify if you meant it.

After chmod -x b.txt the same commit went through. A hook in .git/hooks is yours only; to share it, put it in a folder in the repo and point core.hooksPath at it. Agents can skip hooks with --no-verify, so see stop a coding agent skipping git hooks if that happens.

Ask the agent not to#

Add a line to your project instructions: "Don't change file permissions. If a script needs to be executable, say so and run it with its interpreter (sh build.sh, node script.js) instead." Running a script through its interpreter doesn't need the executable bit, so the agent rarely needs chmod at all.

Before you commit an agent's work, git diff --summary is a quick check for this and for files it created or deleted. For a full look at what changed during a run, see reviewing PRs from several agents.

Frequently asked questions#

What does "old mode 100644 new mode 100755" mean in git?#

The file became executable. Its contents didn't change; 100644 is a normal file and 100755 an executable one.

How do I undo file mode changes in git but keep my edits?#

Run chmod -x on the files listed by git diff --summary as "mode change 100644 => 100755". Their edits stay; only the mode change goes.

Should I set core.fileMode to false?#

Only for a copy of a repository on a drive that can't store the executable bit. It hides all mode changes, including ones you want; mark those with git update-index --chmod=+x.

How do I make a file executable in git on Windows?#

Run git update-index --chmod=+x on the file and commit. git ls-files -s then shows 100755.