git checkout到较早的分支不会更改代码

时间:2018-11-08 04:17:44

标签: git

我有3个分支用于项目回购。

主 v1 v2

现在在本地,就像在v2中一样,我想回到v1分支。所以我

  "dependencies": {
    "@types/jquery": "^3.3.22",
    "@types/react": "^16.4.18",
    "@types/react-dom": "^16.0.9",
    "bootstrap": "^4.1.3",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.4",
    "react": "^16.6.0",
    "react-dom": "^16.6.0"
  },
  "devDependencies": {
    "autoprefixer": "^9.3.1",
    "awesome-typescript-loader": "^5.2.1",
    "css-loader": "^1.0.1",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.10.0",
    "postcss-loader": "^3.0.0",
    "sass-loader": "^7.1.0",
    "source-map-loader": "^0.2.4",
    "style-loader": "^0.23.1",
    "typescript": "^3.1.6",
    "typings-for-css-modules-loader": "^1.7.0",
    "webpack": "^4.25.1",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.10"
  }

我在终端$git checkout v1 中甚至在原子编辑器中都看到了输出,它表明它在分支v1中。但是代码不会回到Switched to branch v1状态。我尝试关闭编辑器并重新打开项目,但是没有运气。

我想念什么?

1 个答案:

答案 0 :(得分:1)

如果您在V2中有未跟踪的文件,而您正尝试检出V1,那么您的未跟踪的文件也将在分支V1中结束。

尝试:

git add --all 
git commit -m "commits on V2"

在V2上,然后检出V1