[英]How can I recover files I deleted locally but didn't yet commit?
I have this situation: 我有这种情况:
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
Is there a way that I can recover back these files that I just deleted. 有没有一种方法可以恢复刚刚删除的这些文件。 Not sure if this helps but the origin still has the latest version of those files. 不确定这是否有帮助,但原始服务器仍具有这些文件的最新版本。
You can start by following the prompt message and try: 您可以按照提示信息开始尝试:
git reset HEAD -- Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
That should unstage the deletion and restore the file with: 这应该取消删除的阶段并使用以下命令还原文件:
git checkout -- Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
As commented by torek, this could be done in one step: 正如torek所说,这可以一步完成:
git checkout HEAD -- Ja/Views/CardsTab/Xaml/Actions/QuizActions.xaml
If you haven't changed anything and you just want to update from remote origin branch you can do 如果您没有进行任何更改,而只想从远程起源分支进行更新,则可以执行
git reset --hard HEAD
git pull
and you will be synced with remote origin 并且您将与远程来源同步
BEWARE though : all your local changes will be lost with reset --hard 但是请注意 :您所有的本地更改都将通过reset --hard丢失
If you need to save changes do 如果您需要保存更改,请执行
git stash
git pull
now check the files are on their place 现在检查文件是否在原位
and apply the stash if you need it 并在需要时应用隐藏
git stash pop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.