简体   繁体   English

无法更改分支 - package-lock.json 被跟踪?

[英]Unable to change branch - package-lock.json being tracked?

I am working on a PHP / JavaScript web app.我正在开发一个 PHP/JavaScript 网络应用程序。 I am trying to change branch but I get the following error:我正在尝试更改分支,但出现以下错误:

error: Your local changes to the following files would be overwritten by checkout:
package-lock.json

I could revert the changes in this file but I don't want to break the application!我可以还原此文件中的更改,但我不想破坏应用程序! Would appreciate any advice offered...将不胜感激提供任何建议...

There are a couple different options.有几个不同的选择。 If you don't want to keep your package-lock.json changes and just want to switch to the other branch because you know its working, you can do one of the following:如果您不想保留 package-lock.json 更改并且只想切换到另一个分支,因为您知道它的工作原理,您可以执行以下操作之一:

git checkout -f branchname

Which does a force checkout into your branch, or the more verbose哪个强制结帐到您的分支,或者更详细

git reset --hard
git checkout branchname

The top command will reset your current branch to the state of the current commit, discarding your changes. top 命令将您当前的分支重置为当前提交的状态,丢弃您的更改。 Then you can check out to the branch you want as normal.然后你可以像往常一样结账到你想要的分支。

If you want to keep your changes because you think you might need them in the future- you can stash them away and bring them back up when needed如果您想保留您的更改,因为您认为将来可能需要它们 - 您可以将它们藏起来并在需要时将它们带回来

git stash 

git checkout branchname

..  (do whatever you want with the branch you switched to)

git pop

Stash isn't specific to any branches- so if you need it in the branch you switched to you can pop it off. Stash 并不特定于任何分支 - 因此,如果您在切换到的分支中需要它,则可以将其弹出。 Or, if you need it in your current branch, you can checkout- do what you need to- then come back and pop it off and continue in basically the same state you're currently in或者,如果您在当前分支中需要它,您可以结帐-做您需要做的事情-然后返回并将其弹出并继续以您当前所处的基本相同的状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM