git 在 Egit 中恢复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4627644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git revert in Egit
提问by Christian
Is it possible to do "git revert"s in Egit to rollback changes by creating a new commit (as opposed to checking out an older commit or doing a hard reset which doesn't create a new commit rolling back the changes)?
是否可以在 Egit 中执行“git revert”以通过创建新提交来回滚更改(而不是检查旧提交或执行不创建新提交回滚更改的硬重置)?
This seems like an important feature if you have a central repository in case you ever need to undo changes that has already been pushed there.
如果您有一个中央存储库,这似乎是一个重要的功能,以防您需要撤消已经推送到那里的更改。
Thanks in advance!
提前致谢!
采纳答案by VonC
If you consider this commit from 5 days ago, called ' Merge "Implement a revert command"' (Shawn Pearce), it seems it will be available soon.
如果您考虑5 天前的此提交,称为“合并“实施恢复命令””(Shawn Pearce),它似乎很快就会可用。
The diff are here:
该DIFF在这里:
public class RevertCommandTest extends RepositoryTestCase {
@Test
public void testRevert() throws IOException, JGitInternalException,
GitAPIException {
Git git = new Git(db);
writeTrashFile("a", "first line\nsec. line\nthird line\n");
git.add().addFilepattern("a").call();
git.commit().setMessage("create a").call();
writeTrashFile("b", "content\n");
git.add().addFilepattern("b").call();
git.commit().setMessage("create b").call();
writeTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
git.add().addFilepattern("a").call();
git.commit().setMessage("enlarged a").call();
writeTrashFile("a",
"first line\nsecond line\nthird line\nfourth line\n");
git.add().addFilepattern("a").call();
RevCommit fixingA = git.commit().setMessage("fixed a").call();
writeTrashFile("b", "first line\n");
git.add().addFilepattern("b").call();
git.commit().setMessage("fixed b").call();
git.revert().include(fixingA).call();
assertTrue(new File(db.getWorkTree(), "b").exists());
checkFile(new File(db.getWorkTree(), "a"),
"first line\nsec. line\nthird line\nfourth line\n");
Iterator<RevCommit> history = git.log().call().iterator();
assertEquals("Revert \"fixed a\"", history.next().getShortMessage());
assertEquals("fixed b", history.next().getFullMessage());
assertEquals("fixed a", history.next().getFullMessage());
assertEquals("enlarged a", history.next().getFullMessage());
assertEquals("create b", history.next().getFullMessage());
assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext());
}
}
回答by Matthias Sohn
- install latest nightly of EGit (0.11.xx)
- open History View
- right-click on the commit you want to revert in the currently checked out branch
- click "Revert Commit"
- 安装最新的 EGit (0.11.xx) 每晚
- 打开历史视图
- 在当前签出的分支中右键单击要还原的提交
- 单击“还原提交”
-- Matthias
——马蒂亚斯
回答by Joel Bricker
I can't comment due to low reputation, but I wanted to add the final piece to @Matthias Sohn's answer just in case anyone, like me, finds this via searching for how to do this. His steps are here below so you don't have to scroll:
由于声誉低,我无法发表评论,但我想将最后一部分添加到@Matthias Sohn 的答案中,以防万一像我这样的人通过搜索如何做到这一点找到了这一点。他的步骤在下面,所以你不必滚动:
- install latest nightly of EGit (0.11.xx)
- open History View
- right-click on the commit you want to revert in the currently checked out branch
- click "Revert Commit"
- 安装最新的 EGit (0.11.xx) 每晚
- 打开历史视图
- 在当前签出的分支中右键单击要还原的提交
- 单击“还原提交”
This will add an entry at the top of the history view "Revert [previous commit comment]". If you right click this new entry you will see an option to commit the Revert operation. You need to do it from the History view because as @Lennon said, you cannot commit and push from the Package Explorer.
这将在历史视图的顶部添加一个条目“Revert [previous commit comment]”。如果您右键单击这个新条目,您将看到一个提交还原操作的选项。您需要从 History 视图中执行此操作,因为正如@Lennon 所说,您无法从 Package Explorer 提交和推送。
The downside to this method is it will Revert all changes in the Commit. I would prefer to be able to rollback only a specific file that was in a Changeset, so if anyone knows of a way to do this please add on.
这种方法的缺点是它会还原提交中的所有更改。我希望能够仅回滚变更集中的特定文件,因此如果有人知道这样做的方法,请添加。
回答by Hau Le
Right click file which you want to revert -> Replace With -> HEAD revision
右键单击要还原的文件 -> 替换为 -> HEAD 修订版