開発中にファイルのモードchmod
を777に変更する必要があるプロジェクトがありますが、メインリポジトリでは変更しないでください。
Gitchmod -R 777 .
はすべてのファイルを取得し、変更済みとしてマークします。ファイルに加えられたモード変更をGitに無視させる方法はありますか?
試す:
git config core.fileMode false
core.fileMode Tells Git if the executable bit of files in the working tree is to be honored. Some filesystems lose the executable bit when a file that is marked as executable is checked out, or checks out a non-executable file with executable bit on. git-clone(1) or git-init(1) probe the filesystem to see if it handles the executable bit correctly and this variable is automatically set as necessary. A repository, however, may be on a filesystem that handles the filemode correctly, and this variable is set to true when created, but later may be made accessible from another environment that loses the filemode (e.g. exporting ext4 via CIFS mount, visiting a Cygwin created repository with Git for Windows or Eclipse). In such a case it may be necessary to set this variable to false. See git-update-index(1). The default is true (when core.filemode is not specified in the config file).
フラグを使用して、-c
1回限りのコマンドにこのオプションを設定できます。
git -c core.fileMode=false diff
を入力するの-c core.fileMode=false
は面倒なので、すべてのgitリポジトリまたは1つのgitリポジトリにこのフラグを設定できます。
# this will set your the flag for your user for all git repos (modifies `$HOME/.gitconfig`)
git config --global core.fileMode false
# this will set the flag for one git repo (modifies `$current_git_repo/.git/config`)
git config core.fileMode false
さらに、Gitグローバルcore.fileModeで説明されているように、リポジトリ構成git clone
でgit init
明示的にに設定core.fileMode
すると、クローンでローカルにfalseがオーバーライドされますtrue
core.fileMode
これはベストプラクティスではないため、慎重に使用する必要があります。この設定は、モードの実行可能ビットのみを対象とし、読み取り/書き込みビットは対象としません。多くの場合chmod -R 777
、すべてのファイルを実行可能にするなどの操作を行ったため、この設定が必要だと思います。ただし、ほとんどのプロジェクトでは、ほとんどのファイルはセキュリティ上の理由から実行可能である必要はなく、実行可能であってはなりません。
この種の状況を解決する適切な方法は、次のように、フォルダとファイルのアクセス許可を別々に処理することです。
find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write
core.fileMode
その場合、非常にまれな環境を除いて、を使用する必要はありません。
作業ツリーのモード変更を元に戻す:
git diff --summary | grep --color 'mode change 100755 => 100644' | cut -d' ' -f7- | xargs -d'\n' chmod +x
git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | xargs -d'\n' chmod -x
またはmingw-gitで
git diff --summary | grep 'mode change 100755 => 100644' | cut -d' ' -f7- | xargs -e'\n' chmod +x
git diff --summary | grep 'mode change 100644 => 100755' | cut -d' ' -f7- | xargs -e'\n' chmod -x
すべてのリポジトリにこのオプションを設定する場合は、このオプションを使用してください--global
。
git config --global core.filemode false
これが機能しない場合は、おそらく新しいバージョンのgitを使用しているので、この--add
オプションを試してください。
git config --add --global core.filemode false
--globalオプションを指定せずに実行し、作業ディレクトリがリポジトリでない場合は、次のようになります。
error: could not lock config file .git/config: No such file or directory
もしも
git config --global core.filemode false
動作しません。手動で実行してください。
cd into yourLovelyProject folder
.gitフォルダーにcd:
cd .git
構成ファイルを編集します。
nano config
trueからfalseに変更
[core]
repositoryformatversion = 0
filemode = true
->
[core]
repositoryformatversion = 0
filemode = false
保存して終了し、上のフォルダに移動します。
cd ..
gitを再初期化する
git init
完了です!
Greg Hewgillの回答に追加する(構成core.fileMode
変数を使用する):
git update-index--chmod=(-|+)x
(「gitadd」の低レベルバージョン)のオプションを使用して、インデックスの実行権限を変更できます。インデックスの実行権限は、「git commit -a」ではなく、「gitcommit」を使用した場合に取得されます。 ")。
グローバルに構成できます。
git config --global core.filemode false
上記がうまくいかない場合は、ローカル構成がグローバル構成をオーバーライドしていることが原因である可能性があります。
ローカル構成を削除して、グローバル構成を有効にします。
git config --unset core.filemode
または、ローカル構成を適切な値に変更することもできます。
git config core.filemode false
すでにchmodコマンドを使用している場合は、ファイルの違いを確認してください。以前のファイルモードと現在のファイルモードが表示されます。
新しいモード:755
古いモード:644
以下のコマンドを使用して、すべてのファイルの古いモードを設定します
sudo chmod 644 .
コマンドまたは手動で構成ファイルのcore.fileModeをfalseに設定します。
git config core.fileMode false
次に、chmodコマンドを適用して、次のようなすべてのファイルのアクセス許可を変更します。
sudo chmod 755 .
そして再びcore.fileModeをtrueに設定します。
git config core.fileMode true
ベストプラクティスでは、core.fileModeを常にfalseにしないでください。
次のエイリアスを(〜/ .gitconfigで)定義することにより、gitコマンドごとにfileModeを一時的に簡単に無効にすることができます。
[alias]
nfm = "!f(){ git -c core.fileMode=false $@; };f"
このエイリアスの前にgitコマンドを付けると、ファイルモードの変更は、それ以外の場合に表示されるコマンドでは表示されません。例えば:
git nfm status
設定ファイル(サブモジュールを含む)でfilemodeをfalseに設定する場合:
find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'
簡単な解決策:
プロジェクトフォルダでこのシンプルなコマンドを押します(元の変更は削除されません) ...プロジェクトフォルダのアクセス許可を変更したときに行われた変更のみが削除されます
コマンドは以下のとおりです。
git config core.fileMode false
このすべての不要なファイルが変更される理由:commend sudo chmod -R777./yourProjectFolder を使用してプロジェクトフォルダーのアクセス許可を変更したため
いつ変更をチェックしますか?gitdifffilenameを使用しているときに以下のように見つかりました
old mode 100644
new mode 100755
これは私のために働きます:
find . -type f -exec chmod a-x {} \;
または逆に、オペレーティングシステムに応じて
find . -type f -exec chmod a+x {} \;
これはうまくいくかもしれません:git config core.fileMode false