繁体   English   中英

签出之前的 git 提交,现在无法切换回 HEAD

[英]Checked out previous git commit, now can't switch back to HEAD

在我的 React Native 项目中,我使用git checkout <previous commit SHA>检查了之前的 git 提交,然后尝试使用git checkout <most recent commit SHA>返回 HEAD。 它说error: Your local changes to the following files would be overwritten by checkout: android/gradlew.bat. Please commit your changes or stash them before you switch branches. error: Your local changes to the following files would be overwritten by checkout: android/gradlew.bat. Please commit your changes or stash them before you switch branches. 我做了git stash然后git checkout <most recent commit SHA>再次,但它给了我同样Your local changes错误。

我怎样才能回到 HEAD?

假设您确实想保留您的更改(否则只是git reset --hard HEAD ),您可以切换到一个新分支( git switch -c [new name here] ),在那里提交更改,然后返回您的main分支并如上所述对HEAD执行硬重置。 我不确定为什么存储对您不起作用,但这应该将您的更改保存在新分支中,将您带回到main中的HEAD ,然后允许您在分支中合并您认为合适的更改(可能需要一个变基)。

暂无
暂无

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

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