2016-08-24 17 views
1

これは何度も起こります。 私のフレームワークが私のシステム上で新しいファイルを作る時、私はgitの状態をして、 "変更された"と見えますが、それらをgitに追加/変更したくないので、 gitignoreファイル、そう? しかし、ときに私は、彼らはまだ私のgitの状態で表示されていることを実行します。だから私はことを試みた無視されたファイルは変更されたまま表示されますが、インデックスから削除すると、他のマシンで削除されます。

https://stackoverflow.com/questions/9750606/git-still-shows-files-as-modified-after-adding-to-gitignore#=

を::S だから私はこの問題を探し、そして出会った

git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 

Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     modified: bootstrap/cache/services.php <<< so these 3 are already in gitignore, but still shows up :S 
     modified: composer.lock <<< so these 3 are already in gitignore, but still shows up :S 
     modified: npm-debug.log <<< so these 3 are already in gitignore, but still shows up :S 

no changes added to commit (use "git add" and/or "git commit -a") 
folder/projectfolder git rm -r --cached bootstrap/cache/services.php 
rm 'bootstrap/cache/services.php' 
folder/projectfolder git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 

Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     deleted: bootstrap/cache/services.php 

Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     modified: composer.lock 
     modified: npm-debug.log 

folder/projectfolder git rm -r --cached composer.lock 
rm 'composer.lock' 
folder/projectfolder git rm -r --cached npm-debug.log 
rm 'npm-debug.log' 
folder/projectfolder git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 

Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     deleted: bootstrap/cache/services.php 
     deleted: composer.lock 
     deleted: npm-debug.log 

folder/projectfolder git commit -m "clean gitindex" 
[master 084a4e1] clean gitindex 
Committer: ******** 

3 files changed, 13823 deletions(-) 
delete mode 100644 bootstrap/cache/services.php 
delete mode 100644 composer.lock 
delete mode 100644 npm-debug.log 
folder/projectfolder git status 
On branch master 
Your branch is ahead of 'origin/master' by 2 commits. 
    (use "git push" to publish your local commits) 

nothing to commit, working directory clean 
folder/projectfolder git push 
warning: <<<message and login removed here>>> 
Counting objects: 9, done. 
Compressing objects: 100% (6/6), done. 
Writing objects: 100% (6/6), 582 bytes | 0 bytes/s, done. 
Total 6 (delta 4), reused 0 (delta 0) 
To https://*****@bitbucket.org/*****/*****.git 
    45ty54y4y54y******y4t43at master -> master 

をしかし、私の同僚がgitから自分の変更を引き出すと、gitインデックスだけでなく、3つのファイルが実際に自分のシステムから削除されます。どのようにマシン上のファイルシステムに触れることなく、gitをgitignoreのすべてのファイルを無視するようにするにはどうすればいいですか? 、と言ってP

バート

答えて

1

申し訳ありませんが、

は、実は私は唯一の「あなたのたわごとを修正して行くと、あなたは物事が変化していることを教えて前に無視するファイルを見てください、ちょっとgitの」コマンドを必要としますこれが期待どおりに機能していることを確かめてください。

git rm --cachedを実行したときに、gitインデックス、つまりリポジトリからファイルを削除するように指示しますが、ローカルバージョン(ローカルファイルシステム上のファイル)はそのままにしておきます。その結果、彼らはあなたのマシン上にまだ生きていますが、相手のマシン上ではgit pull/rebaseの一部として取り除かれます。

はまだここにファイル必要は、ソースコントロールに存在するかどうかの大きな問題があり、変更するかどうかは確かでは無視すべきです。その質問は本当にあなたとあなたのチームだけが答えられることができます。

ソースコントロール内に存在するが必要ですが、それに行われた変更は、を無視しなければならないファイルは、その後、私が過去に使用している一つの技術は、の一環として、それらのファイルのgit revertを行うのであれば私が使っているビルドプロセス。たとえば、psake、gulp、またはCakeスクリプト内では、git revertをプロセスの最後のステップとして実行します。

このテクニックは、AssemblyInfo.csファイルをソース管理で使用する必要がある場合に使用しましたが、ビルドプロセスの一環として、このファイルは現在のバージョン番号で更新されています。開発者マシンでビルドをローカルで実行しているときに、変更を変更セットに含めないようにしましたので、ビルドプロセスで追加のステップを使用してgit revertに変更しました。

+0

ありがとうございました。 gitに "ステータスファイル"を更新させて(おそらくそのインデックスと呼ばれていない?)、ignoreファイルを調べる方法は他にありますか?私はちょうどgitが "無視されたファイルで何もしません。ファイル名が意味するように、ちょうど無視して、変更されたことを私に伝えません。私のためにそれを無視して、私がgitステータスを行うときに私にその変更を教えてください... " –

+0

ファイルがgitインデックスに追加されると、ファイルへの変更は' git status'に表示されます.gitignoreファイルに表示されます。これを防ぐための唯一の方法は、上記のようにファイルをインデックスから削除し、.gitignoreに追加することです。しかし、その時点で、ファイルはリポジトリに存在しません。ここには何もありません。ファイルはリポジトリに存在し、変更を追跡しているか、変更を追加して無視します。 –

+0

ファイルを追加するHADがあるのに、変更をコミットしたくない場合は、実行しているビルドスクリプトの一部として 'git revert'を追加して、そのファイルに対する変更を常に元に戻す。 –

関連する問題