Effectively revert to a previous commit in Sourcetree.

huangapple go评论54阅读模式
英文:

Effectively revert to a previous commit in Sourcetree

问题

我正在尝试实际恢复到以前的提交,有效地取消掉在它之后所做的每一个更改,并将这个以前的提交作为当前提交,位于列表的顶部。

但是,当我使用“将当前分支重置到此提交”功能时,我就无法做任何操作,直到我将所有我试图取消的提交都拉回来。

我觉得很多人在其他帖子的评论中问了完全相同的问题,但他们从未得到明确的答案。执行这个操作的步骤是什么?

英文:

I am trying to actually revert to a previous commit, effectively cancelling every change that has been made after it, and making this previous commit the current one, at the top of the list.

But when I use the function "Reset current branch to this commit", I am then unable to do anything until I pull back all of the commits I am trying to cancel.

I feel like a lot of people have been asking that exact same question in the comments of other posts, but they never receive a clear answer. What is the procedure for doing this?

答案1

得分: 0

不要取消/删除以下提交,那么在这种情况下,我不会使用“重置当前分支到此提交”。

我会打开终端并输入 git checkout c17c46e ./(将 c17c46e 替换为实际的提交哈希值)。
<br> ./ 下的文件(即所有已跟踪的文件)将会恢复到它们的旧状态。<br>
./ 是必需的,以防它只是切换到较早的位置并创建一个分离的 HEAD。

此外,不必手动输入提交哈希值,您可以右键单击提交并点击 '复制 SHA 到剪贴板'。

运行该命令后,您可以提交结果并将其推送到远程。

英文:

Since you don't want to cancel/delete the following commits, I wouldn't use "Reset current branch to this commit" at all in that case.

I would open the Terminal and enter git checkout c17c46e ./ (replace c17c46e with the actual commit hash).
<br>The files under ./ (i.e. all the tracked files) will be changed to their older states.<br>
The ./ is necessary so that it doesn't simply switch to an earlier position and create a detached head.

Also, the commit hash doesn't have to be typed manually, as you can right click a commit and click 'Copy SHA to Clipboard'.

After running that command, you can commit the results and push it to the remote.

huangapple
  • 本文由 发表于 2023年3月7日 10:35:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657572.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定