前言
有些时候咱们不想将本地文件或文件夹提交到git近程仓库,这个时候咱们怎么做呢?咱们以前端我的项目中的config.js为例来阐明。
操作
1、疏忽本地文件
比方:近程仓库config.js
export default {
host: 'http://baidu.com'
}
我本地的config.js
export default {
host: 'http://localhost:8080'
}
当初咱们应用命令git pull origin master
的时候,会呈现抵触,所以咱们不想提交本地的config.js永远不同步近程仓库外面的config.js,咱们能够如下操作:
git update-index --assume-unchanged config.js
update-index –assume-unchanged的作用就是疏忽本地文件,这样咱们add和commit的时候就不会提交到线上了。
2、获取线上更新
尽管咱们胜利疏忽了config.js文件,然而有时候咱们又想获取最新的配置内容,但又不想提交,这个时候咱们能够应用上面操作命令:
// 解除本地疏忽
git update-index --no-assume-unchanged config.js
// 暂存
git stash
// 拉取线上更新(这个时候把想要的配置复制下来)
git pull origin master
// 复原本地配置(把下面的配置粘贴过去)
git stash apply
// 从新疏忽
git update-index --assume-unchanged config.js
// 提交
git push origin develop
总结
1、疏忽本地文件和文件夹很好的解决不想同步某些配置文件。
2、疏忽本地文件夹
git update-index --assume-unchanged floder/ <疏忽文件夹>
留神:疏忽文件夹时。前面的斜杠‘/’肯定要带上,否则会报错:fatal: Unable to mark file sessions
援用
git谬误解决:Your local changes to the following files would be overwritten by merge
发表回复