简体   繁体   English

如何在git中“撤消撤消”?

[英]How do I “undo an undo” in git?

To reset my last commit, I did this: 要重置我的上一次提交,我这样做:

git reset --soft HEAD^

But I did it too many times. 但是我做了很多次。 Now I want to go back forward a couple. 现在,我想回头几个。 Is that possible? 那可能吗?

Also, I had a developer pull and merge code on a production application that completely hosed up everything. 另外,我让开发人员在生产应用程序上提取并合并代码,从而完全完成了所有工作。 Then to fix it, he manually overwrote some files in the app source. 然后要解决此问题,他手动覆盖了应用程序源中的某些文件。 There are bad commits. 有错误的提交。 The applications is not functioning. 应用程序无法运行。

Is there some way to do a hard reset to a particular point in time in Git? 在Git中,有什么方法可以硬重置到特定的时间点吗? I am not familiar enough with it. 我对它还不够熟悉。

Use git reflog to see where you were and reset to that. 使用git reflog查看您的位置并重置为该位置。 (or use notation like HEAD@{1} in reset ) (或在RESET中使用HEAD@{1}类的符号)

For the other issue, from git log get the hash of the commit you want to reset to and do git reset --hard <sha1> . 对于另一个问题,从git log获取要重置为的提交的哈希值,然后执行git reset --hard <sha1> Or you can even do git reset --hard HEAD@{1 day ago} etc. if you wanted to reset to some commit some time in the past. 或者,如果您想过去重设一些提交,甚至可以执行git reset --hard HEAD@{1 day ago}等。 Since you are rewriting history, you will have to do a force push - git push -f 由于您要重写历史记录,因此必须强制执行git push -f

Also, why are developers pushing to production? 另外,为什么开发人员要投入生产? Have gates - CI, testing, etc. 有门-CI,测试等

Is there some way to do a hard reset to a particular point in time in Git? 在Git中,有什么方法可以硬重置到特定的时间点吗?

Yes. 是。 git reset --hard <SHA1-id-of-the-commit-you-want-to-hard-reset-to>

See here (Undoing in Git - Reset, Checkout and Revert) for more on git reset . 有关git reset更多信息,请参见此处(在Git中撤消-重置,签出和还原) To learn the basics of data recovery, please see here: Data Recovery Section in Chapter 9 of ProGit book . 要了解数据恢复的基础知识,请参见ProGit手册第9章中的“数据恢复”部分

Few more hints on how to undo things in git . 关于如何在git中撤消操作的更多提示。

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

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