撤消更改git(不重写历史记录) [英] Undo change in git (not rewriting history)

查看:96
本文介绍了撤消更改git(不重写历史记录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在脚本中做了一个改变,并付诸实践。然后我做了一些其他的更改,并将它们推送到远程存储库等。

然后我意识到,我提到的第一个变化是愚蠢的,想要撤消它。 。我可以unapply那个提交,而不需要手动复制/粘贴diff吗?

举个例子:我有两个文件, a.py b.py

 提交1:
我在a.py

中删除了一个函数Commit 2:
我在b.py中修改了几行

Commit 3:
我改变a.py
中的文档字符串

我可以撤销该功能删除吗?显示为提交4(而不是删除提交1)

解决方案

是的,您可以使用为此。有关详情,请参阅 git手册部分



要点是你可以说:

  git revert 4f4k2a 

其中4f4k2a是要撤消的提交的ID,它将尝试撤消它。


I made a change in a script and committed it. Then I made a few other changes, and pushed them to a remote repository and such.

Then I realised that first change I mentioned was stupid, and want to undo it.. Can I "unapply" that commit, without manually copy/pasting the diff?

As an example: I have two files, a.py and b.py:

Commit 1:
I delete a function in a.py

Commit 2:
I change a few lines in b.py

Commit 3:
I change the docstring in a.py

Can I undo that function deletion, and make it appear as "commit 4" (rather than deleting commit 1)

解决方案

Yes, you can use git revert for this. See the git manual section on this for more information.

The gist is that you can say:

git revert 4f4k2a

Where 4f4k2a is the id of the commit you'd like to undo, and it will try to undo it.

这篇关于撤消更改git(不重写历史记录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆