-
-
Save jtdp/5443498 to your computer and use it in GitHub Desktop.
git diff -p \ | |
| grep -E '^(diff|old mode|new mode)' \ | |
| sed -e 's/^old/NEW/;s/^new/old/;s/^NEW/new/' \ | |
| git apply |
Thanks! appreciate the help.
thanks. very helpful for me.
it just applies (revert) only file mode changes (diff|(old|new) mode).
Thanks a lot.
Any ideas on how to filter out files that have changes in their content?
For example, I want all the files with permissions changes but not if they also have changes in their content
Excelent!
If you have configured an external diff tool, i recommend you to add the --no-ext-diff parameter to avoid it to open that tool a billion times:
git diff --no-ext-diff -p -R --no-color
| grep -E "^(diff|(old|new) mode)" --color=never
| git apply
Seems to fail on deleted files, this resolve that
Command
git diff -p --no-ext-diff --no-color --diff-filter=d | grep -E "^(diff|old mode|new mode)" | sed -e "s/^old/NEW/;s/^new/old/;s/^NEW/new/" | git apply
Git Alias
git config --global --add alias.permission-resetb '!git diff -p --no-ext-diff --no-color --diff-filter=d | grep -E "^(diff|old mode|new mode)" | sed -e "s/^old/NEW/;s/^new/old/;s/^NEW/new/" | git apply'
Seems to fail on deleted files, this resolve that
Command
git diff -p --no-ext-diff --no-color --diff-filter=d | grep -E "^(diff|old mode|new mode)" | sed -e "s/^old/NEW/;s/^new/old/;s/^NEW/new/" | git apply
Git Alias
git config --global --add alias.permission-resetb '!git diff -p --no-ext-diff --no-color --diff-filter=d | grep -E "^(diff|old mode|new mode)" | sed -e "s/^old/NEW/;s/^new/old/;s/^NEW/new/" | git apply'
Not working(
What if it was commited and pushed? I've one commit with more than 3000 file permissions changed (mixed with real content changes). What I can do to revert the file permissions?
I was able to restore permissions from a previous commit doing this:
git ls-tree -r d3fb093 |while read mode _ _ fpath; do chmod "${mode:3}" "$fpath"; done
where d3fb093
is the last commit with the right permissions.
tahnks! ;)
Awesome!
If this solution does not work for you, I have found two possible causes -
- Your git clone is on an ExFAT formatted volume. There is no fix for this, and no commands will help. ExFAT doesn't support file permissions. You can only configure git to ignore file permissions, or reformat the drive using something more suitable.
- Your git clone is on a volume shared via Apple File Sharing and has an ACL at the root of the volume. If that's you, good luck, and I have no idea, but maybe this tip will send you in the right direction!
It isn't a solution, in that it doesn't change or fix file permissions, but if you are stuck with one of the above, it may ease the pain to set:
git config core.fileMode false
though using this setting is highly not recommended generally.
@martynov-dm you should run git permission-resetb
not git apply
Just in case
-p
option is not about 'permissions', it is about 'patch'. Also this option is used by default, so can be omited.https://git-scm.com/docs/git-diff
Also in pointed topic, there is an improvement: