git 在 Egit 中恢复

发布于 2024-10-10 17:30:11 字数 144 浏览 3 评论 0原文

是否可以在 Egit 中执行“git revert”,通过创建新提交来回滚更改(而不是签出旧提交或进行硬重置,而硬重置不会创建新提交来回滚更改)?

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

提前致谢!

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)?

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

拥抱影子 2024-10-17 17:30:11
  • 安装最新的 EGit (0.11.xx) 每晚版本
  • 打开历史记录视图
  • 右键单击​​当前签出分支中要还原的提交
  • 单击“还原提交”

--
马蒂亚斯

  • 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"

--
Matthias

杀お生予夺 2024-10-17 17:30:11

如果您认为此 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());
       }
}

If you consider this commit from 5 days ago, called ' Merge "Implement a revert command" ' (Shawn Pearce), it seems it will be available soon.

The 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());
       }
}
独行侠 2024-10-17 17:30:11

由于声誉较低,我无法发表评论,但我想将最后一部分添加到 @Matthias Sohn 的答案中,以防万一像我这样的人通过搜索如何执行此操作找到此内容。他的步骤如下,因此您不必滚动:

  • 安装最新的 EGit (0.11.xx) 每晚版
  • 打开历史记录视图
  • 右键单击​​要在当前签出的分支中恢复的提交
  • 单击“恢复提交”

这将在历史视图顶部添加一个条目“恢复[先前提交评论]”。如果右键单击这个新条目,您将看到一个用于提交恢复操作的选项。您需要从“历史记录”视图中执行此操作,因为正如@Lennon 所说,您无法从“包资源管理器”中提交和推送。

此方法的缺点是它将恢复提交中的所有更改。我希望能够仅回滚变更集中的特定文件,因此如果有人知道执行此操作的方法,请添加。

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:

  • 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"

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.

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.

一曲琵琶半遮面シ 2024-10-17 17:30:11

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

Right click file which you want to revert -> Replace With -> HEAD revision

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文