0

有两个分支masterand dist,都有/node_modulesin 的入口.gitignore

在两个分支中都没有未提交/未跟踪的文件,当我在 master 上时,如果我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 被忽略了,但不知何故,当切换回 master 时,一些子文件夹被删除了。

4

1 回答 1

0

(从评论中简要扩展)

Git 用于.gitignore知道哪些未版本控制的文件应该被单独保留。但是,如果文件已经被版本化,它们是 repo 的一部分,git 不会简单地跳过这些文件。在您的情况下,您的 dist 分支包含不属于 master 分支的文件,因此当您从 dist 切换到 master 时,这些文件将被删除。您找到的解决方案,从 dist 分支中删除这些文件,是正确的:大概,这些文件是.gitignore因为它们不应该是 repo 的一部分,并且您修复了 repo,以便这些文件确实不是它的一部分.

于 2013-09-26T11:09:59.207 回答