我已开始处理某个项目,并且我已将.idea/*
添加到 .gitignore 文件中,但它仍然显示出来。
所以我认为该文件必须在git缓存中,所以我运行git rm --cached filename
,虽然它似乎不起作用,因为它在合并分支时实际删除了文件,你可以在下面看到我的git命令。
我最近开始开发一个macbook pro,在我开始使用ubuntu之前,我从未遇到过这个问题。也许这与我的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
答案 0 :(得分:2)
rm --cached
会在暂存区域中将文件标记为已删除。下次提交时,删除将记录在存储库的历史记录中。
如果您然后将此提交合并到另一个分支,则该文件将从磁盘中删除(因为Git合并您的分支,然后检出生成的树)。