2011-01-07 64 views
10

是否有可能在Egit中执行“git revert”以通过创建新提交来回滚更改(与检出较旧的提交或执行不会创建新提交滚动的硬重置相反)回到更改)?git revert in Egit

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

在此先感谢!

回答

3

如果你认为这个commit from 5 days ago,叫做'合并'实施恢复命令“”(肖恩皮尔斯),它似乎很快就会提供。

diff are here

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()); 
     } 
} 
+0

我想这证实它根本不可能。谢谢! – Christian 2011-01-08 12:55:30

10
  • 安装例如:It(0.11.xx)
  • 开放的历史记录查看最新的夜间
  • 右键单击提交要在当前签出恢复分支
  • 点击“恢复提交”

- 马蒂亚斯

+0

我这样做了,但后来我无法提交并推送到远程存储库。我想要一个特定的老提交成为头... – Lennon 2012-09-24 18:16:35

1

我不能因低信誉发表评论,但我想补充的最后一块@Matthias孙某的回答,以防万一有人和我一样,通过寻找如何做到这一点认为这。他的脚步在此下方,这样你就不必滚动:

  • 安装例如:It(0.11.xx)
  • 开放的历史记录查看最新的夜间对
  • 右键单击要恢复在提交目前已签出分支
  • 点击“还原提交”

这将会在历史视图顶部添加一个条目“还原[先前提交注释]”。如果你右键点击这个新条目,你会看到一个选项来提交恢复操作。您需要从历史记录视图执行此操作,因为@Lennon说,您无法从包资源管理器进行提交和推送。

这种方法的缺点是它会恢复Commit中的所有更改。我宁愿能够只回滚一个Changeset中的特定文件,所以如果有人知道这样做的方式,请添加。

0

右键单击要恢复的文件 - >替换为 - > HEAD修订版