Git命令git update-index --assume-u

2022-02-14  本文已影响0人  Angel_6c4e
应用场景:

我们在自己的私有测试分支上调试项目逻辑,给文件做了一些特定的修改,但是文件不想被git提交,不想执行git status命令时出现在modified列表里;再比如,我们本地的数据库和测试环境的数据库配置是不一样的,但是在项目开发中每次提交过程中忽略数据库配置文件。那么你这里就可以把不想提交的文件忽略。

当然关于git忽略文件的方式有很多,我这里使用的是git update-index --assume-unchanged命令。

代码举例:
Administrator@USER-20180915BE MINGW64 /e/数梦工场/uniapp/alipay-miniprogram (fsy-branch)
$ git status  //执行git status 命令,私有分支修改过两个文件
On branch fsy-branch
Your branch is up to date with 'origin/fsy-branch'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   common/api.js
        modified:   pagesU/liquorLicense/liquorLicense.vue

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

//执行忽略命令,注意文件的路径,否则会报错
Administrator@USER-20180915BE MINGW64 /e/数梦工场/uniapp/alipay-miniprogram (fsy-branch)
$ git update-index --assume-unchanged common/api.js //忽略api.js文件

Administrator@USER-20180915BE MINGW64 /e/数梦工场/uniapp/alipay-miniprogram (fsy-branch)
$ git status   //验证文件是否被忽略
On branch fsy-branch
Your branch is up to date with 'origin/fsy-branch'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   pagesU/liquorLicense/liquorLicense.vue //验证成功,api.js成功被忽略

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

Administrator@USER-20180915BE MINGW64 /e/数梦工场/uniapp/alipay-miniprogram (fsy-branch)
$ git update-index --no-assume-unchanged common/api.js  //恢复跟踪

Administrator@USER-20180915BE MINGW64 /e/数梦工场/uniapp/alipay-miniprogram (fsy-branch)
$ git status  //再次验证
On branch fsy-branch
Your branch is up to date with 'origin/fsy-branch'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   common/api.js  //恢复成功
        modified:   pagesU/liquorLicense/liquorLicense.vue 

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

猜你喜欢

热点阅读