git提交时如何忽略.idea文件 以及如何在已经提交的情况下再次忽略.idea文件
- 打开.gitignore文件,添加所有idea文件,如下:
#pycharm .idea
mall/.idea/*
.idea/*
注意:由于.idea为pycharm自动生成的文件,该步一定要在用pycharm打开工程之前操作,即系统创建.idea文件之前。
2. 若已经提交过.idea文件,则进行如下步骤:
- 多次查看都已经有哪些.idea文件,并进行抛弃
涉及的命令有
git status
git checkout .idea/workspace.xml
git checkout mall.idea/workspace.xml 忽略所有idea文件的改变
G:\shunyi__git_42>git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitignore
new file: .idea/misc.xml
new file: .idea/modules.xml
new file: .idea/shunyi__git_42.iml
new file: .idea/vcs.xml
new file: .idea/workspace.xml
new file: mall/.idea/workspace.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: mall/.idea/workspace.xml
G:\shunyi__git_42>git checkout mall/.idea/workspace.xml
G:\shunyi__git_42>git statua
git: 'statua' is not a git command. See 'git --help'.
The most similar command is
status
G:\shunyi__git_42>git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitignore
new file: .idea/misc.xml
new file: .idea/modules.xml
new file: .idea/shunyi__git_42.iml
new file: .idea/vcs.xml
new file: .idea/workspace.xml
new file: mall/.idea/workspace.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: .idea/workspace.xml
G:\shunyi__git_42>git checkout .idea/workspace.xml
G:\shunyi__git_42>git status
On branch master
Your branch is up to date with 'origin/master'.
- 删除仓库目录下的idea 和 工程 目录下的idea
- 在.gitignore文件中加入所有目录下的idea文件,如下:
#pycharm .idea
mall/.idea/*
.idea/*
- git status 查看追踪文件,这时候发现追踪文件有修改.gitignore文件和删除.idea文件,如下:
G:\shunyi__git_42>git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitignore
new file: .idea/misc.xml
new file: .idea/modules.xml
new file: .idea/shunyi__git_42.iml
new file: .idea/vcs.xml
new file: .idea/workspace.xml
new file: mall/.idea/workspace.xml
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .gitignore
deleted: .idea/misc.xml
deleted: .idea/modules.xml
deleted: .idea/shunyi__git_42.iml
deleted: .idea/vcs.xml
deleted: .idea/workspace.xml
deleted: mall/.idea/workspace.xml
- 将所作修改提交到码云
git add .
git status
git commit -m "删除之前idea文件"
git push
- 重新打开pycharm,这时候发现mall目录下pyharm重新创建了idea文件
- git status 检查是否成功忽略所有idea文件,没有新的追踪则成功忽略