2016-04-01 13 views
0

私はプロジェクトの作業を開始しましたが、.gitignoreファイルに.idea/*を追加しましたが、まだ表示されています。git rm --cachedはファイルシステムからファイルを削除しています

私はgit rm --cached filenameを実行したので、ファイルがgitキャッシュに入っていなければならないと思っていましたが、ブランチをマージすると実際にファイルが削除されてしまいました。

私は最近、私がubuntuで作業する前に、MacBookプロで開発を始めましたが、この問題は一度もありませんでした。おそらくそれは私のgitセットアップと関係があります。

これは以前私がgit rm --cached .を実行したときに、実際にファイルシステムからほとんどのプロジェクトファイルを削除した別のプロジェクトで発生しました。

$ (786-rwd) git status 
On branch 786-rwd 
Your branch is up-to-date with 'origin/786-rwd'. 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    deleted: .idea/misc.xml 

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: .gitignore 
    modified: .idea/modules.xml 
    modified: .idea/www.project.dev.iml 
    modified: app/design/frontend/bootstrapped/rwd/template/prog/bund.phtml 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    skin/frontend/bootstrapped/rwd/sass/_cms-pages.scss 

holy in ~/ubuntu_1404/httpdocs/porject 
$ (786-rwd) git rm --cached .idea/modules.xml 
rm '.idea/modules.xml' 
holy in ~/ubuntu_1404/httpdocs/porject 
$ (786-rwd) git rm --cached .idea/www.project.dev.iml 
rm '.idea/www.project.dev.iml' 

$ (786-rwd) git status 
On branch 786-rwd 
Your branch is up-to-date with 'origin/786-rwd'. 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    deleted: .idea/misc.xml 
    deleted: .idea/modules.xml 
    deleted: .idea/www.project.dev.iml 

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: app/design/frontend/bootstrapped/rwd/template/prog/bund.phtml 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    skin/frontend/bootstrapped/rwd/sass/_cms-pages.scss 

holy in ~/ubuntu_1404/httpdocs/porject 
$ (786-rwd) ls .idea/ 
./      .name     deployment.xml   encodings.xml   scopes/     workspace.xml 
../      copyright/    dictionaries/   modules.xml    vcs.xml     www.project.dev.iml 

$ (786-rwd) git add . 
holy in ~/ubuntu_1404/httpdocs/project 
$ (786-rwd) git commit -m 'theming & cleaned up git' 
[786-rwd 8aa5ba8] theming & cleaned up git 
5 files changed, 24 deletions(-) 
delete mode 100644 .idea/misc.xml 
delete mode 100644 .idea/modules.xml 
delete mode 100644 .idea/www.project.dev.iml 
create mode 100644 skin/frontend/bootstrapped/rwd/sass/_cms-pages.scss 
holy in ~/ubuntu_1404/httpdocs/project 
$ (786-rwd) git status 
On branch 786-rwd 
Your branch is ahead of 'origin/786-rwd' by 1 commit. 
    (use "git push" to publish your local commits) 
nothing to commit, working directory clean 
holy in ~/ubuntu_1404/httpdocs/project 
$ (786-rwd) git checkout -b test-branch origin/prod 
Branch test-branch set up to track remote branch prod from origin. 
Switched to a new branch 'test-branch' 
holy in ~/ubuntu_1404/httpdocs/project 
$ (test-branch) git merge --no-ff 786-rwd 
Auto-merging app/design/frontend/bootstrapped/mobile/template/program/results.phtml 
Auto-merging app/design/frontend/bootstrapped/default/template/page/html/header.phtml 
Removing .idea/www.project.dev.iml 
Removing .idea/modules.xml 
Removing .idea/misc.xml 
Merge made by the 'recursive' strategy. 
.gitignore                   | 6 +- 
.idea/misc.xml                  | 5 - 
.idea/modules.xml                 | 9 - 
.idea/www.project.dev.iml              | 9 - 
app/design/frontend/bootstrapped/default/layout/local.xml       | 66 ++++ 


$ (test-branch) ls .idea/ 
./    ../    .name   copyright/  deployment.xml dictionaries/ encodings.xml scopes/   vcs.xml   workspace.xml 

答えて

2

rm --cachedは、ファイルをステージング領域で削除済みとしてマークします。次にコミットすると、その削除はリポジトリの履歴に記録されます。 このコミットを別のブランチにマージすると、そのファイルはディスクから削除されます(Gitはブランチをマージしてツリーをチェックアウトします)。

+0

どうすればgitにファイルを無視させることができますか?既にgitignoreに追加しました – Holly

+0

削除がすべてのブランチに記録されたら、それは将来の操作で無視されるべきです。残念ながら、これは予想される動作です。 – knittl

+0

ファイルをgitで無視したいが、各環境ファイルシステムに残しておきたい場合は 'rm --cached'を実行し、ファイルシステム上のファイルを' git merge'で削除した後で置き換える必要がありますか? – Holly

関連する問題