有两个分支master和dist,两个分支都在.gitignore中有/node_modules条目。
在两个分支中都没有未提交/未跟踪的文件,而且当我在主服务器上时,如果我执行git checkout dist,然后再次使用git checkout master,我会看到一些文件夹消失了,但是并不是所有的
下面是包含命令的流:
~/p/retwisn git:master ❯❯❯ git status
# On branch master
nothing to commit, working directory clean
~/p/retwisn git:master ❯❯❯ tree node_modules -L 1
node_modules
├── connect-flash
├── connect-redis
├── express
├── grunt
├── grunt-coffeelint
├── grunt-concurrent
├── grunt-contrib-clean
├── grunt-contrib-coffee
├── grunt-contrib-copy
├── grunt-contrib-watch
├── grunt-mocha-cli
├── grunt-nodemon
├── grunt-shell
├── jade
├── mocha
├── redis
├── redis-url
├── should
├── sinon
├── swagger-node-express
└── yaml-config
~/p/retwisn git:master ❯❯❯ git checkout dist
~/p/retwisn git:dist ❯❯❯ git status
# On branch dist
nothing to commit, working directory clean
~/p/retwisn git:dist ❯❯❯ tree node_modules -L 1
node_modules
├── connect-flash
├── connect-redis
├── express
├── grunt
├── grunt-coffeelint
├── grunt-concurrent
├── grunt-contrib-clean
├── grunt-contrib-coffee
├── grunt-contrib-copy
├── grunt-contrib-watch
├── grunt-mocha-cli
├── grunt-nodemon
├── grunt-shell
├── jade
├── mocha
├── redis
├── redis-url
├── should
├── sinon
├── swagger-node-express
└── yaml-config
~/p/retwisn git:dist ❯❯❯ git checkout master
~/p/retwisn git:master ❯❯❯ git status
# On branch master
nothing to commit, working directory clean
~/p/retwisn git:master ❯❯❯ tree node_modules -L 1
node_modules
├── grunt-contrib-clean
├── grunt-nodemon
└── swagger-node-express虽然/node_modules被忽略了,但是当切换回主时,一些子文件夹被删除了。
发布于 2013-09-26 11:09:59
(从评论中简要扩展)
Git使用.gitignore来知道哪些不版本的文件应该单独保存。但是,如果文件已经版本化,它们是回购的一部分,而git将不会简单地跳过这些文件。在您的示例中,dist分支包含不属于主分支的文件,因此当您从dist切换到master时,这些文件将被删除。您找到的解决方案是从dist分支中删除这些文件,这是正确的解决方案:想必,这些文件在.gitignore中,因为它们不应该是回购的一部分,并且您修复了回购,以便这些文件确实不是其中的一部分。
https://stackoverflow.com/questions/19025220
复制相似问题