git提交时如何忽略.idea文件 以及如何在已经提交的情况下再次忽略.idea文件

git提交时如何忽略.idea文件 以及如何在已经提交的情况下再次忽略.idea文件

  1. 打开.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文件,没有新的追踪则成功忽略
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值