如何反转 git 中的提交列表?
我有一个带有 git 的源代码树,我需要撤销自 9 月份以来所做的所有更改,我知道提交的 id,并且我还可以生成要使用 git rev-list 恢复的提交列表,问题是我如何将该列表提供给 git 以便它取消所有这些列表?
或者如果有更好的方法来做到这一点,我将非常感激。
I have a source tree with git and I need to reverse all my changes that I have done since September, I know the id of the commit, and I can also generate a list of commits that I want to revert with git rev-list, the question is how do I feed that list to git so that it uncommits all of them?
Or if there is a better way to do this I would really appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想销毁自给定提交以来的所有更改,您可以将您正在处理的分支(例如 master)重置为该提交。
git reset
的作用是将您的HEAD
移动到给定的提交。以下提交将被丢弃。然后
给你:
--hard
用于丢弃索引和本地文件中最近的更改。如果您有多个分支,这可能会变得有点复杂,但您明白了。
请注意,丢弃的提交可以通过 git reflog 恢复,但如果您不尝试的话,您不太可能看到它们。最终,丢弃的提交将永远消失,特别是如果您偶尔使用 git gc 。
If you want to destroy all changes since a given commit, you can reset the branch you are working on (for example master) to the commit. What
git reset <commit>
does is that it moves yourHEAD
to the given commit. The following commits get discarded.then
gives you:
--hard
is for discarding your recent changes from the index and your local files.If you have multiple branches, this might get a bit more complicated, but you get the idea.
Note that the discarded commits may be recoverable with
git reflog
, but you won't be likely to see them if you're not trying to. Eventually, the discarded commits will disappear for good, especially if you're usinggit gc
now and then.