我如何将修改的文件转换为以前的修订,在一个特定的 commit hash (我通过 git log 和 git diff 确定)?


当前回答

git log --oneline  // you see commits, find commit hash to which you want reset
git diff y0urhash src/main/.../../YourFile.java   // to see difference
git reset y0urhash src/main/.../../YourFile.java   // revert to y0urhash commit
git status                                        // check files to commit
git commit -m "your commit message"
git push origin

其他回答

这是一个非常简单的步骤. 检查文件到我们想要的承诺ID,这里一个承诺ID之前,然后只是 git承诺修改,我们已经完成了。

# git checkout <previous commit_id> <file_name>
# git commit --amend

如果我们想把任何文件带到承诺的顶部的任何先前承诺 ID,我们可以轻松地做到。

如果您正在使用 Git Extensions 并只想返回文件的父母承诺,您可以选择包含您想要返回的更改的承诺,然后在详细信息面板中选择“Diff”选项卡,右键单击您想要返回的文件,然后“返回文件(s)到”....,然后“A”(父母)

git checkout ref♰commitHash -- filePath

吉。

git checkout HEAD~5 -- foo.bar
or 
git checkout 048ee28 -- foo.bar

这对我工作:

git checkout <commit hash> file

接下来的改变:

git commit -a

有趣的是, git checkout foo 如果工作副本在一个名为 foo 的目录中工作,则不会工作;但是, git checkout HEAD foo 和 git checkout./foo 都会:

$ pwd
/Users/aaron/Documents/work/foo
$ git checkout foo
D   foo
Already on "foo"
$ git checkout ./foo
$ git checkout HEAD foo