git在Egit中恢复

Chr*_*ian 10 eclipse git egit

是否有可能在Egit中执行"git revert"以通过创建新提交来回滚更改(而不是检查较旧的提交或执行硬重置,而不会创建新的提交以回滚更改)?

如果您有一个中央存储库,以防您需要撤消已经推送的更改,这似乎是一个重要的功能.

提前致谢!

小智 10

  • 安装最新的EGit(0.11.xx)
  • 打开历史视图
  • 右键单击要在当前签出的分支中还原的提交
  • 点击"还原提交"

- 马蒂亚斯


Von*_*onC 3

如果您考虑5 天前的这个提交,称为“合并”实施恢复命令”(Shawn Pearce),那么它似乎很快就会可用。

差异在这里

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());
       }
}
Run Code Online (Sandbox Code Playgroud)