简体   繁体   English

如何恢复在本地删除但尚未提交的文件?

[英]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.

相关问题 我对许多文件进行了更改,但尚未提交。 我如何撤出所有更改? - I made changes to a lot of files but didn't yet do a commit. How can I back out of all the changes? 我如何通过Git查找谁在本地删除了几个重要文件(尚未上演) - How can I find via Git who deleted a couple of important files locally (hasn't been staged yet) 我如何退出我所做但尚未在我的 GITHUB 分支中提交的一些更改 - How can I back out of some changes I made but didn't yet commit in my GITHUB branch 如何恢复 Git 中丢失的提交? - How can I recover a lost commit in Git? 如何不将本地删除的文件提交到git - How to NOT commit locally deleted files to git 我用-d删除了一个分支,如何恢复/恢复它? - I deleted a branch with -d, how can I restore/recover it? 如何恢复在git中删除的文件 - How can I recover the file I deleted in git 如何恢复更改后尚未提交的本地删除文件 - How to recover locally deleted files that has not been committed after changes 如何恢复从远程本地存储库中删除的文件,以及将来如何防止这种丢失? - How can I recover files deleted from both my remote an local repositories and how can I prevent this loss in the future? 如果用命令写的git commit消息,我该如何澄清尚未完成的内容? &#39;不要添加散列&#39;或&#39;没有/不添加散列&#39;? - If git commit messages written in the imperative, how do I clarify what hasn't yet been done? 'Don't add hashing' or 'Didn't/Doesn't add hashing'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM