2613

開発中にファイルのモードchmodを777に変更する必要があるプロジェクトがありますが、メインリポジトリでは変更しないでください。

Gitchmod -R 777 .はすべてのファイルを取得し、変更済みとしてマークします。ファイルに加えられたモード変更をGitに無視させる方法はありますか?

4

12 に答える 12

4350

試す:

git config core.fileMode false

git-config(1)から:

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).

フラグを使用して、-c1回限りのコマンドにこのオプションを設定できます。

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 clonegit 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その場合、非常にまれな環境を除いて、を使用する必要はありません。

于 2009-10-16T21:53:40.683 に答える
300

作業ツリーのモード変更を元に戻す:

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
于 2010-01-18T02:20:15.120 に答える
148

すべてのリポジトリにこのオプションを設定する場合は、このオプションを使用してください--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
于 2012-04-21T12:00:50.843 に答える
104

もしも

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

完了です!

于 2013-08-06T13:10:33.580 に答える
56

Greg Hewgillの回答に追加する(構成core.fileMode変数を使用する):

git update-index--chmod=(-|+)x (「gitadd」の低レベルバージョン)のオプションを使用して、インデックスの実行権限を変更できます。インデックスの実行権限は、「git commit -a」ではなく、「gitcommit」を使用した場合に取得されます。 ")。

于 2009-10-16T22:03:24.293 に答える
44

グローバルに構成できます。

git config --global core.filemode false

上記がうまくいかない場合は、ローカル構成がグローバル構成をオーバーライドしていることが原因である可能性があります。

ローカル構成を削除して、グローバル構成を有効にします。

git config --unset core.filemode

または、ローカル構成を適切な値に変更することもできます。

git config core.filemode false

于 2015-01-21T09:12:25.527 に答える
26

すでに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にしないでください。

于 2015-10-13T07:34:57.597 に答える
22

次のエイリアスを(〜/ .gitconfigで)定義することにより、gitコマンドごとにfileModeを一時的に簡単に無効にすることができます。

[alias]
nfm = "!f(){ git -c core.fileMode=false $@; };f"

このエイリアスの前にgitコマンドを付けると、ファイルモードの変更は、それ以外の場合に表示されるコマンドでは表示されません。例えば:

git nfm status
于 2015-07-24T15:01:35.293 に答える
14

設定ファイル(サブモジュールを含む)でfilemodeをfalseに設定する場合: find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'

于 2013-07-16T12:23:45.793 に答える
7

簡単な解決策:

プロジェクトフォルダでこのシンプルなコマンドを押します(元の変更は削除されません) ...プロジェクトフォルダのアクセス許可を変更したときに行われた変更のみが削除されます

コマンドは以下のとおりです。

git config core.fileMode false

このすべての不要なファイルが変更される理由:commend sudo chmod -R777./yourProjectFolder を使用してプロジェクトフォルダーのアクセス許可を変更したため

いつ変更をチェックしますか?gitdifffilenameを使用しているときに以下のように見つかりました

old mode 100644
new mode 100755
于 2018-03-19T13:13:57.230 に答える
3

これは私のために働きます:

find . -type f -exec chmod a-x {} \;

または逆に、オペレーティングシステムに応じて

find . -type f -exec chmod a+x {} \;
于 2018-04-30T15:06:11.083 に答える
2

これはうまくいくかもしれません:git config core.fileMode false

于 2021-12-28T18:16:07.180 に答える