发现某个文件被错误的提交了,这个文件还是和其它代码一起提交的,如何还原一下呢?
命令格式:
git checkout commitid $mypath/$myfile
具体案例:
git log $mypath/$myfile
commit dfae8363665910df65409d29ff6c9263a1866c65
Author: xx <xxx>
Date: Fri May 8 20:53:49 2020 +0800
this is commit log2
commit 0688360b09a72b1b197f9f52a5b39ac82d282285
Author: yy <yyy>
Date: Wed Feb 5 15:45:35 2020 +0800
this is commit log2
git checkout 0688360b09a72b1b197f9f52a5b39ac82d282285 $mypath/$myfile
Updated 1 path from cc47c81
操作完上述步骤后$mypath/$myfile
已经还原了,不过需要你重新将还原后的文件commit及push远程才会保存到远程仓库中。