首页  

git恢复删除的文件     所属分类 git 浏览量 1146
不小心删除了某些文件,在未提交的情况下
使用以下命令恢复 
git checkout -- .

git checkout -- 与 git checkout 的区别

If you have an unfortunate branch that is named hello.c, 
this step would be confused as an instruction to switch to that branch. You should instead write:

git checkout -- hello.c

使用 -- 解决 分支名 和文件名相同的情况 


拉取暂存区文件 替换工作区文件
git checkout -- $file  
 
拉取最近一次提交到版本库的文件到暂存区 , 不影响工作区
git reset HEAD  -- $file  

工作区乱了  ,拉取 暂存区 恢复工作区


git rm note.txt
# 无法使用 git checkout .  恢复
git reset HEAD .
git checkout .



rm note.txt
# 注意 git rm  与 rm 的区别  , git rm 会影响暂存区
git status

Changes not staged for commit:
  (use "git add/rm $file..." to update what will be committed)
  (use "git checkout -- $file..." to discard changes in working directory)

	deleted:    note.txt
	
# 添加到暂存区
git add note.txt
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD $file..." to unstage)

	deleted:    note.txt


恢复 note.txt 到暂存区
git reset HEAD note.txt

恢复到工作区
git checkout note.txt

上一篇     下一篇
redis脚本实例

redis pipeline 与 lua 比较

redis slow log

git branch 和 git checkout常见用法

hive数据仓库

Zookeeper在HBase中的应用