简体   繁体   English

撤消git或tortoisegit中的revert

[英]undo revert in git or tortoisegit

Is there an easy way to undo a tortoisegit revert? 是否有一种简单的方法来撤消tortoisegit还原?

Here's more info: I just committed a large multi-file checkin, and right afterwards decided I instead wanted to commit a separate small checkin before the big one, to make it easier to amend that big checkin tomorrow. 这里有更多信息:我刚刚提交了一个大型的多文件签入,之后我决定在大版本之前提交一个单独的小签到,以便更容易修改明天的大签入。

So I brought up the log in tortoisegit, right-clicked on the last checkin, and chose "revert". 所以我提起登录tortoisegit,右键点击最后一次检查,然后选择“恢复”。 This undid the changes and deleted a bunch of files in my working directory. 这解决了更改并删除了我工作目录中的一堆文件。 What I really wanted was "reset" (roll back a checkin and leave my working directory as is), not revert (create an "undo checkin" in my working directory). 我真正想要的是“重置”(回滚签到并按原样保留我的工作目录),而不是恢复(在我的工作目录中创建“撤销签入”)。

How can I undo my revert? 如何撤消我的恢复?

After more Googling, I found the answer in this blog post : simply run the revert command again and it will undo your revert without littering your history with any extra commits. 经过更多谷歌搜索,我在这篇博文中找到了答案:只需再次运行revert命令,它将撤消你的恢复,而不会乱丢你的历史记录与任何额外的提交。 It's as if I'd never run revert in the first place. 就好像我从来没有在第一时间运行恢复。

The blog post only mentions this trick for regular (command-line) git, but the same thing works in tortoisegit. 博客文章只提到常规(命令行)git的这个技巧,但同样的事情在tortoisegit中起作用。 What's particularly nice is that other changes in my working directory are not blown away-- only the revert is undone. 特别好的是,我的工作目录中的其他更改不会被吹走 - 只有恢复被撤消。

I'm leaving the self-generated Q&A pair here, since it was kinda hard to find this answer-- hopefully will help someone else save time. 我要离开这里自行生成的Q&A对,因为很难找到这个答案 - 希望能帮助别人节省时间。

Just git reset to the point you wanted to, anyway. 无论如何,只需将git reset为您想要的点。 A revert is nothing special: it is just a normal commit which does the exact opposite of what another commit does. revert并不是什么特别的事情:它只是一个正常的提交,与另一个提交完全相反。 Since it is just a normal commit, it will be garbage collected just like the other commit(s) you originally wanted to get rid of. 因为它只是一个普通的提交,所以它将被垃圾收集,就像你最初想要摆脱的其他提交一样。

I tried reverting a commit that I had previously reverted, and it did nothing. 我试图恢复我之前恢复的提交,但它没有做任何事情。 The result was "nothing to commit (working directory clean)". 结果是“没有提交(工作目录清理)”。

What did work was cherry-picking the formerly reverted commit. 什么工作是挑选以前恢复的提交。 That pulled in the changes that I had formerly reverted and did not otherwise alter my working directory. 这引起了我之前恢复的变化,并没有改变我的工作目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM