[英]I made changes to a lot of files but didn't yet do a commit. How can I back out of all the changes?
[英]How can I recover files I deleted locally but didn't yet commit?
我有這種情況:
MacBook:Ja.git alan$ git status
On branch alan-1
Your branch is up to date with 'origin/alan-1'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
deleted: Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml.cs
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Ja/App/SetResourceColors.cs
modified: Ja/App/Styles.cs
modified: Ja/Templates/Button/Button.xaml.cs
modified: Ja/Views/CardsTab/CardsTab.xaml
modified: Ja/Views/CardsTab/Xaml/Actions/Actions.xaml
有沒有一種方法可以恢復剛剛刪除的這些文件。 不確定這是否有幫助,但原始服務器仍具有這些文件的最新版本。
您可以按照提示信息開始嘗試:
git reset HEAD -- Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
這應該取消刪除的階段並使用以下命令還原文件:
git checkout -- Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
正如torek所說,這可以一步完成:
git checkout HEAD -- Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
如果您沒有進行任何更改,而只想從遠程起源分支進行更新,則可以執行
git reset --hard HEAD
git pull
並且您將與遠程來源同步
但是請注意 :您所有的本地更改都將通過reset --hard丟失
如果您需要保存更改,請執行
git stash
git pull
現在檢查文件是否在原位
並在需要時應用隱藏
git stash pop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.