是否可以在egit中执行“git revert”,通过创建新的提交来回滚更改(而不是签出旧的提交或执行不创建新提交的硬重置来回滚更改)?
如果您有一个中央存储库,这似乎是一个重要的特性,以防您需要撤消已经被推到那里的更改。
事先谢谢!
最佳答案
如果考虑到这个名为“merge”implement a revert command“'(shawn pearce)的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());
}
}