简体   繁体   English

如何使用EGit将所有文件还原到以前的提交?

[英]How do I revert all files to a previous commit using EGit?

I am using EGit 2.2.0.20-1212191850-r with GitHub. 我正在GitHub上使用EGit 2.2.0.20-1212191850-r。 All of my local files are committed and pushed. 我所有的本地文件都已提交并推送。 There is only the master branch. 只有master分支。 I would like to permanently revert all of my files to a previous commit (not HEAD~1). 我想将所有文件永久还原到以前的提交(而不是HEAD〜1)。 How do I do it? 我该怎么做?

Here's what I have tried: 这是我尝试过的:

  1. I opened the History pane, where I see all past commits. 我打开了“历史记录”窗格,在其中可以看到所有过去的提交。
  2. I right-clicked on the earlier commit and selected Reset > Hard. 我右键单击较早的提交,然后选择“重置”>“硬”。
  3. I see the old version. 我看到了旧版本。 I try committing the old version but none of the changed files show up in the Commit Changes window, even if I explicitly add them to the index. 我尝试提交旧版本,但是即使已将它们明确添加到索引中,也没有任何更改的文件显示在“提交更改”窗口中。

I also tried Checkout in step 2, with the same result. 我还在步骤2中尝试了Checkout,结果相同。

Eclipse git checkout (aka, revert) is not relevant, since it is just about reverting to HEAD, not an earlier commit. Eclipse git checkout(又名revert)无关紧要,因为它只是恢复到HEAD,而不是更早的提交。

What I'd really like to do is create a new branch from the earlier commit, but I'll settle for reverting. 我真正想做的是从先前的提交中创建一个新分支,但我会进行恢复。

If you already pushed the commits, it is generally recommended to revert the commits. 如果您已经推送了提交,通常建议还原提交。 The reason for that is that revert will add new commits to the history instead of replacing the history, which makes it possible for other people to just pull instead of having to rebase on the replaced history. 这样做的原因是,还原将向历史记录添加新的提交,而不是替换历史记录,这使得其他人可以只提取而不需要基于替换的历史记录。

So in the History view, select the newest commit you want to undo, open the context menu and select "Revert". 因此,在“历史记录”视图中,选择要撤消的最新提交,打开上下文菜单,然后选择“还原”。 Repeat for the parent commits. 对父提交重复以上操作。 When you're done, push the result. 完成后,推送结果。

Also note that "git checkout" and "git revert" are different things, "git revert" creates a new commit that undos the changes of a previous commit. 还要注意,“ git checkout”和“ git revert”是不同的东西,“ git revert”创建一个新的提交,该撤消撤消先前提交的更改。 "git checkout" on the other hand changes the working directory or current branch to a commit. 另一方面,“ git checkout”将工作目录或当前分支更改为提交。 You may be confused because "svn revert" does what "git checkout" does, not "git revert". 您可能会感到困惑,因为“ svn revert”执行的是“ git checkout”,而不是“ git revert”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM