After copying the git project, the file permissions were inexplicably modified (mode change 100644 => 100755). How to deal with it?

After copying a batch of git projects from one device to another, no modifications were made to the files. However, when entering the root directory of the project and executing, it was git statusfound that the status of all files was modified.

It feels weird

Execution git diff --summaryfound that most of the time mode change 100644 => 100755, it turned out that during the process of copying the file, the permissions of the file were automatically modified, and the permission value changed from 644 to 755.

How to deal with this situation?

Turn off git filemode

  • global shutdown
git config --global core.filemode false
  • single project close
git config core.filemode false

Modify file permissions (this method is recommended)

git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | tr '\n' '\0' | xargs -0 chmod -x
git diff --summary | grep --color 'mode change 100755 => 100644' | cut -d' ' -f7- | tr '\n' '\0' | xargs -0 chmod -x
 git diff --summary | grep --color 'mode change 100644 => 100755'                 
 mode change 100644 => 100755 .gitignore
 mode change 100644 => 100755 Makefile
 mode change 100644 => 100755 pom.xml
  • cut -d' ' -f7-

Cut the text with spaces to get the value in column 7 (the subscript starts from 1, f1 is the complete character channel). That is, the full path of the file.

git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7-
.gitignore
Makefile
pom.xml
  • tr '\n' '\0'

\nChange the delimiter from\0

git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | tr '\n' '\0'
.gitignoreMakefilepom.xml
  • xargs -0 chmod -x

will be \0used as delimiter

Modify the file permissions of all files that meet the conditions

git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | tr '\n' '\0' | xargs -0 chmod -x

Check whether the modification is successful

git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7-

Opposite operation

Add permissions to files

git diff --summary | grep --color 'mode change 100755 => 100644' | cut -d' ' -f7- | tr '\n' '\0' | xargs -0 chmod +x

Guess you like

Origin blog.csdn.net/uwoerla/article/details/131058037