git 如何还原某个文件


目的

想把文件 include/plugin/funclib/function_member.php 恢复到 b257f8685b71a471c4f797d05f52a1a576047ed2 (2014-12-29 23:38)这个版本,但是使用 git reset b257f8685b71a471c4f797d05f52a1a576047ed2 include/plugin/funclib/function_member.php 一直无法实现。

代码


 
Administrator@USER-20140115FZ /D/website/xxx.com/www (master) $ git log include/plugin/funclib/function_member.php commit bbb0a005d245e6d5ef5b1c0b1b0ef2981fa3ecb9 Author: ken <[email protected]> Date: Mon Jan 5 22:07:37 2015 +0800 for reset commit b257f8685b71a471c4f797d05f52a1a576047ed2 Author: ken <[email protected]> Date: Mon Dec 29 23:38:09 2014 +0800 add reg forbbiden commit 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b Author: ken <[email protected]> Date: Mon Dec 29 21:51:44 2014 +0800 add coname filter for register commit 53298e00de944863f6092d0d4c0a260d00124f9f Author: ken <[email protected]> Date: Mon Dec 29 01:24:13 2014 +0800 add referrals.php delete some php files like serv.php yqm.php,modify registe commit 44118e5256eb9786d024f9b7d2dfb8af0bd8a308 Author: default7 <[email protected]> Date: Sun Jul 27 17:05:21 2014 +0800 first commit Administrator@USER-20140115FZ /D/website/xxx.com/www (master) $ git reset b257f8685b71a471c4f797d05f52a1a576047ed2 include/plugin/funclib/fun ction_member.php --hard fatal: Cannot do hard reset with paths. Administrator@USER-20140115FZ /D/website/xxx.com/www (master) $ git reset b257f8685b71a471c4f797d05f52a1a576047ed2 include/plugin/funclib/fun ction_member.php Unstaged changes after reset: M include/plugin/funclib/function_member.php Administrator@USER-20140115FZ /D/website/xxx.com/www (master) $

版本控制 git 版本管理

此ID不存在 11 years, 3 months ago

直接用 git-checkout 即可。理解起来稍微有点奇怪就是了。


 $ git checkout ${commit} /path/to/file

来源参考:

疾风D悠月つ answered 11 years, 3 months ago

git不能把单独的某个文件恢复到指定的版本,如果要这要做,可以这样
1、git reset 版本号,这时候,会产生一个和版本号对应的分支
2、git checkout到这个分支,把要恢复的文件拷贝走
3、git checkout到原来的分支,把文件再拷贝回来,覆盖掉现在的文件,然后git add,git commit

zaku4 answered 11 years, 3 months ago

我觉得使用tortoisegit挺好的啊,配置好之后直接有图形界面,用rever就可以恢复以前版本了

好忧伤躺在地上 answered 11 years, 3 months ago

还需要执行 git checkout xxxxx(文件名)

nanaco answered 11 years, 3 months ago

Your Answer