簡體   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