关于git:Git-忽略项目中某些文件或文件夹

1次阅读

共计 887 个字符,预计需要花费 3 分钟才能阅读完成。

前言

有些时候咱们不想将本地文件或文件夹提交到 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

正文完
 0