Home  >  Q&A  >  body text

github - Git 忽略文件后,切换分支后在其它出现

比如说我的项目有两个分支

    $ git branch
      master
    * dev

dev 分支下面有两个3个文件夹是 ignore 的: bower_components/, node_modules/, dist/.

现在我在 dev 下面提交之后, 切换到 master 分支去,结果在 master 分支下也可以看到 bower_components/, node_modules/, dist/这些目录和里面的文件,是我操作不对吗?如何解决呢?

PHP中文网PHP中文网2727 days ago629

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-05-02 09:30:50

    If these files appear in version management, it’s because

    .gitignore file is in version control

    dev分支下的 .gitignore 记录了你要忽略的文件
    但是在masterUnder the branch, .gitigonre has not recorded the content you want to ignore

    Solution (update master’s .gitignore)

    Method 1. merge dev -> master
    Method 2. add ignore files in .gitignore at master branch

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:30:50

    If you modify the code in one branch and submit it, it will have no impact on other branches. In the same way, if you just ignore the file under the dev branch, it will have no impact on other branches, so what you have to do is to repeat the ignored action on other branches, or merge the changes under the dev branch to other branches. Branch to go.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:30:50

    It’s not that your operation is incorrect, but that after you add it to gitignore, git doesn’t care about these files anymore, so switching does not switch branches, these files are all there

    reply
    0
  • Cancelreply