我的iOS世界

XCode某个文件被物理删除了git恢复方法

2018-04-19  本文已影响0人  ldhonline

一、场景

在XCode的项目树中删除一个文件,不小心点了 Move to Trash。


21849D98-1920-498B-A67F-27FA88ED6943.png

这样这个文件就被物理删除了,还好有 git 大法

二、先看 git status

MyMac:coyote_assistant liudh$ git status
On branch feature_***_ldh
Your branch is up-to-date with 'origin/feature_***_liudh'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    "***********************.m"

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:   ***********************/project.pbxproj
    modified:   ***********************/contents.xcworkspacedata
    modified:   ***********************.xcworkspace/xcuserdata/shuw.xcuserdatad/UserInterfaceState.xcuserstate
    modified:   ***********************/xcdebugger/Breakpoints_v2.xcbkptlist
    modified:   ***********************.m
    modified:   ***********************.h
    modified:   ***********************.m
    .....
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    *** 2018-04-18 14-30-08/

绿色文字就是删除的记录,git其实自带智能提示,上面那一行就是恢复的命令

(use "git reset HEAD <file>..." to unstage)

1、从上一个版本恢复

// 文件名已隐藏,请使用真实文件名
git reset HEAD ******---.m 

执行完后,发现deleted信息已不见了

2、重新迁入文件

git checkout --  .....m 

发现文件回来了。

上一篇 下一篇

猜你喜欢

热点阅读