Coo*_*coa 63 git version-control
我最近向我的分支机构的HEAD提交了一个文件,其中有错误.我需要做以下事情:
最好的方法是什么?
syk*_*ora 97
你几乎是自己说的:
首先从一次提交中获取文件:
$> git checkout HEAD~1 path/to/file.ext
Run Code Online (Sandbox Code Playgroud)
然后提交它:
$> git commit -a -m 'Retrieved file from older revision'
Run Code Online (Sandbox Code Playgroud)
如果只对上一次提交中存在的文件所做的更改,您甚至可以使用git-revert:
$> git revert HEAD
Run Code Online (Sandbox Code Playgroud)
我认为将它作为一个单独的提交会更好,因为它会准确地告诉您恢复的内容以及原因.但是,您可以使用--amend切换将此压缩到上一次提交git-commit.