如何切换分支与添加到.gitignore的文件夹中的更改?

时间:2013-08-16 05:29:41

标签: git

我创建了一个分支临时文件 我安装了较新版本的快递模块。我将node_modules文件夹添加到.gitignore。

[ubuntu@ip-172-31-10-215:~/bitstarter]$git checkout master
error: The following untracked working tree files would be overwritten by checkout:
        node_modules/.bin/express
        node_modules/express/.npmignore
        node_modules/express/History.md
        node_modules/express/LICENSE
        node_modules/express/Makefile
        node_modules/express/Readme.md
        node_modules/express/bin/express
        node_modules/express/index.js
        node_modules/express/lib/express.js
        node_modules/express/lib/request.js
        node_modules/express/lib/response.js
        node_modules/express/lib/router/index.js
        node_modules/express/lib/router/route.js
        node_modules/express/lib/utils.js
        node_modules/express/lib/view.js
        node_modules/express/node_modules/connect/.npmignore
        node_modules/express/node_modules/connect/LICENSE
        node_modules/express/node_modules/connect/index.js
        node_modules/express/node_modules/connect/lib/cache.js
        node_modules/express/node_modules/connect/lib/connect.js
        node_modules/express/node_modules/connect/lib/index.js
        node_modules/express/node_modules/connect/lib/middleware/basicAuth.js
        node_modules/express/node_modules/connect/lib/middleware/bodyParser.js
        node_modules/express/node_modules/connect/lib/middleware/compress.js
        node_modules/express/node_modules/connect/lib/middleware/cookieParser.js
        node_modules/express/node_modules/connect/lib/middleware/csrf.js
        node_modules/express/node_modules/connect/lib/middleware/directory.js
        node_modules/express/node_modules/connect/lib/middleware/errorHandler.js
        node_modules/express/node_modules/connect/lib/middleware/favicon.js
        node_modules/express/node_modules/connect/lib/middleware/limit.js
        node_modules/express/node_modules/connect/lib/middleware/logger.js
        node_modules/express/node_modules/connect/lib/middleware/methodOverride.js
        node_modules/express/node_modules/connect/lib/middleware/query.js
        node_modules/express/node_modules/connect/lib/middleware/responseTime.js
        node_modules/express/node_modules/connect/lib/middleware/session.js
        node_modules/express/node_modules/connect/lib/middleware/session/cookie.js
        node_modules/express/node_modules/connect/lib/middleware/session/memory.js
        node_modules/express/node_modules/connect/lib/middleware/session/session.js
        node_modules/express/node_modules/connect/lib/middleware/session/store.js
        node_modules/express/node_modules/connect/lib/middleware/static.js
        node_modules/express/node_modules/connect/lib/middleware/staticCache.js
        node_modules/express/node_modules/connect/lib/middleware/vhost.js
        node_modules/express/node_modules/connect/lib/patch.js
        node_modules/express/node_modules/connect/lib/public/directory.html
        node_modules/express/node_modules/connect/lib/public/error.html
        node_modules/express/node_modules/connect/lib/public/favicon.ico
        node_modules/express/node_modules/connect/lib/public/icons/page.png
        node_modules/express/node_modules/connect/lib/public/icons/page_add.png
        node_modules/express/node_modules/connect/lib/public/icons/page_attach.png
        node_modules/express/node_modules/connect/lib/public/icons/page_code.png
        node_modules/express/node_modules/connect/lib/public/icons/page_copy.png
        node_modules/express/node_modules/connect/lib/public/icons/page_delete.png
        node_modules/express/node_modules/connect/lib/public/icons/page_edit.png
        node_modules/express/node_modules/connect/lib/public/icons/page_error.png
        node_modules/express/node_modules/connect/lib/public/icons/page_excel.png
        node_modules/express/node_modules/connect/lib/public/icons/page_find.png
        node_modules/express/node_modules/connect/lib/public/icons/page_gear.png
        node_modules/express/node_modules/connect/lib/public/icons/page_go.png
        node_modules/express/node_modules/connect/lib/public/icons/page_green.png
        node_modules/express/node_modules/connect/lib/public/icons/page_key.png
        node_modules/express/node_modules/connect/lib/public/icons/page_lightning.png
        node_modules/express/node_modules/connect/lib/public/icons/page_link.png
        node_modules/express/node_modules/connect/lib/public/icons/page_paintbrush.png
        node_modules/express/node_modules/connect/lib/public/icons/page_paste.png
        node_modules/express/node_modules/connect/lib/public/icons/page_red.png
        nod
Aborting

这是git状态(为了好玩):

[ubuntu@ip-172-31-10-215:~/bitstarter]$git status
# On branch temp
nothing to commit (working directory clean)

晚上1点30分,所以我已经厌倦了,我不能为我的生活找到一个干净的解决方案(害怕失去我的工作或搞乱依赖或其他什么)。
我会明天检查答案非常感谢你!

2 个答案:

答案 0 :(得分:1)

在将规则添加到.gitignore之前,您似乎已经提交了这些文件。

您可以使用git rm --cached <file>将其从Git中删除。

为了使用脏目录切换分支,通常最快和最简单的是stash更改。

答案 1 :(得分:0)

如果刚安装了新版本并且git已经跟踪了以前的文件,则可以解开已添加到git的文件。

git rm --cached filename

Git将停止跟踪这些文件,现在将该文件夹添加到.gitignore。