Gilang Chandrasa Thoughts, stories, and ideas

How to recover file permission in Git

Once in a while I mess up the files permission in a project, if you did what I did and don’t have any change or uncommitted changes then you just go reset to origin.

But if for some reason you can’t do that, here solutions for you.

$ git diff --summary | grep --color 'mode change 100755 => 100644' | cut -d' ' -f7- | xargs chmod 755
$ git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | xargs chmod 644

Or you can use this magic words to restore all the permissions.

$ git diff -p -R --no-color | grep -E "^(diff|(old|new) mode)" --color=never | git apply

Credit: