忽略已追踪文件或者文件夹

刘超 6天前 ⋅ 3693 阅读   编辑

一、描述

  1、如下忽略已追踪.gitignore文件

 

  2、忽略已追踪文件夹

二、分析

  1、向.git/info/exclude文件追加.gitignore内容即可,使用git提供的命令,将.gitignore内容追加到.git/info/exclude文件中,

git update-index --assume-unchanged .gitignore

如下

 

  2、不能使用这种方式来操作,vi .git/info/exclude ,然后添加.gitignore,这种方式不符合git规范

  3、可能会遇到fatal: Unable to mark file .gitignore

  4、使用git update-index --assume-unchanged 文件夹,报

[/Workspace/Learn/dq]$ git update-index --assume-unchanged target*[master]

fatal: Unable to mark file target

  5、网上找到git-update-index-assume-unchanged-on-directory,可以使用如下命令忽略已追踪文件夹

命令1:git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')

命令2:git ls-files | tr '\n' ' ' | xargs git update-index --assume-unchanged

三、解决方法

  文件

    先查看文件是否被追踪;如果.gitignore未追踪,执行echo ".gitignore" >> .gitignore 即可;如果.gitignore被追踪,执行 git update-index --assume-unchanged .gitignore;如果想恢复执行git update-index --no-assume-unchanged .gitignore

  文件夹

    查看文件夹是否被追踪和文件的一样,忽略未追踪文件夹也和文件的一样;忽略被追踪文件夹,执行以下任意命令即可

命令1:git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')

命令2:git ls-files | tr '\n' ' ' | xargs git update-index --assume-unchanged

    忽略已追踪dq-ui文件夹,示例如下

ljc@DESKTOP-US5MR61 MINGW64 /e/Workspace/dq/dq (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
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:   dq-ui/10.c82d18f823c32b78a2b3.chunk.js
        modified:   dq-ui/10.c82d18f823c32b78a2b3.chunk.js.gz
        modified:   dq-ui/11.340834baf17ab6303878.chunk.js
        modified:   dq-ui/12.7c345cc81d0911e2e1a3.chunk.js
        modified:   dq-ui/12.7c345cc81d0911e2e1a3.chunk.js.gz
        modified:   dq-ui/13.e9ef1b186d182577e6fd.chunk.js
        modified:   dq-ui/14.01b5d9d704a266ba9e20.chunk.js
        modified:   dq-ui/15.09e05841ac5400eab6d0.chunk.js
        modified:   dq-ui/16.6de91177cfee80ec8762.chunk.js
        modified:   dq-ui/17.dae3a48fe324443e173a.chunk.js
        modified:   dq-ui/18.2c36d6b255119e079f67.chunk.js
        modified:   dq-ui/19.125d8a8f921d2a671989.chunk.js
        modified:   dq-ui/2.dfca5d4578be964ce0b0.chunk.js
        modified:   dq-ui/20.2ca2cc3fc903f2b5eab4.chunk.js
        modified:   dq-ui/3.6c3b176009d501b3f358.chunk.js
        modified:   dq-ui/8.a2031d489f8994fadfe0.chunk.js
        modified:   dq-ui/8.a2031d489f8994fadfe0.chunk.js.gz
        modified:   dq-ui/9.c26bc3f47b608334db34.chunk.js
        modified:   dq-ui/9.c26bc3f47b608334db34.chunk.js.gz
        modified:   dq-ui/index.html
        modified:   dq-ui/runtime~app.c5cafe897e518f4482c3.js
        modified:   dq-ui/runtime~share.55d3b23a081a0f706b12.js
        modified:   dq-ui/share.28c20180b9ac31b773ac.chunk.js
        modified:   dq-ui/share.28c20180b9ac31b773ac.chunk.js.gz
        modified:   dq-ui/share.html
        modified:   dq-ui/vendor.5cbce7b2f06ee995120f.chunk.js
        modified:   dq-ui/vendor.5cbce7b2f06ee995120f.chunk.js.gz
        modified:   stats.json

no changes added to commit (use "git add" and/or "git commit -a")

ljc@DESKTOP-US5MR61 MINGW64 /e/Workspace/dq/dq (master)
$ cd dq-ui/

ljc@DESKTOP-US5MR61 MINGW64 /e/Workspace/dq/dq/dq-ui (master)
$ git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')

ljc@DESKTOP-US5MR61 MINGW64 /e/Workspace/dq/dq/dq-ui (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

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:   ../stats.json

no changes added to commit (use "git add" and/or "git commit -a")

注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: