2011-01-07 63 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修訂版