我如何将修改的文件转换为以前的修订,在一个特定的 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

其他回答

下面是Rebase如何工作:

git checkout <我的分支> git rebase 主 git checkout 主 git merge <我的分支>


假设你有

───────────────────

... 查看你想向大师分支申请的变革分支。 退缩命令从 <我的分支>(不在大师中找到)采取命令,并将其重新应用到大师的头部。 换句话说,在 <我的分支>中的第一个命令的父母不再是大师历史中的先前命令,而是当前大师的头部。

git rebase master <my branch>

这可能更容易记住这个命令,因为“基础”和“修改”分支都明确。

历史的最终结果是:

────────────────────


git checkout master
git merge <my branch>

...做一个快速前进的合并,将所有 <我的分支> 变更应用于主人. 没有这个步骤,退缩承诺不会添加到主人. 最终结果是:

───────────────────

git branch -d <my branch>

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

如果您想要将文件转换为以前的承诺(并且您想要转换已承诺的文件),您可以使用

git checkout HEAD^1 path/to/file

git checkout HEAD~1 path/to/file

然后,只是步行,并采取“新”版本。

武装着一个承诺可以有两个父母在合并的情况下,你应该知道,头1是第一个父母,头1是第二个父母。

或者它会工作,如果树上只有一个父母。

您可以使用任何引用到一个 git 承诺,包括 SHA-1 如果这是最方便的。

git checkout [commit-ref] -- [文件名]

git checkout ref♰commitHash -- filePath

吉。

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