有些时候咱们不想将本地文件或文件夹提交到git远程仓库,这个时候咱们怎么作呢?咱们之前端项目中的config.js为例来讲明。前端
一、忽略本地文件
好比:远程仓库config.jsgit
export default { host: 'http://baidu.com' }
我本地的config.jssession
export default { host: 'http://localhost:8080' }
如今咱们使用命令git pull origin master
的时候,会出现冲突,因此咱们不想提交本地的config.js永远不一样步远程仓库里面的config.js,咱们能够以下操做:app
git update-index --assume-unchanged config.js
update-index --assume-unchanged的做用就是忽略本地文件,这样咱们add和commit的时候就不会提交到线上了。.net
二、获取线上更新
虽然咱们成功忽略了config.js文件,可是有时候咱们又想获取最新的配置内容,但又不想提交,这个时候咱们可使用下面操做命令:code
// 解除本地忽略 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
一、忽略本地文件和文件夹很好的解决不想同步某些配置文件。
二、忽略本地文件夹blog
git update-index --assume-unchanged floder/ <忽略文件夹> 注意:忽略文件夹时。后面的斜杠‘/’必定要带上,不然会报错:fatal: Unable to mark file sessions
git错误解决:Your local changes to the following files would be overwritten by mergeget