Git 忽略項目中某些文件或文件夾

前言

有些時候咱們不想將本地文件或文件夾提交到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

相關文章
相關標籤/搜索