简体   繁体   English

如何使用SourceTree将Git项目还原到最后的提交状态

[英]How to restore a Git project to the last committed state using SourceTree

Somewhere I made a bunch of changes and I need to go back to an earlier version. 在某个地方,我做了很多更改,需要回到较早的版本。 I copied my current projects out of my local directory that contains the project. 我从包含项目的本地目录中复制了当前项目。 The project contains about 5 directories. 该项目包含约5个目录。 I copied out two of them and then deleted those two folders. 我复制了其中两个,然后删除了这两个文件夹。

I now need to reset back to an earlier version. 我现在需要重置回较早的版本。 I'm using SourceTree and need help to go back to the last commit. 我正在使用SourceTree,需要帮助才能返回到上一次提交。 I double clicked on the tag and it shows this message: 我双击标签,它显示以下消息:

在此处输入图片说明

I don't know what that means so I selected the second to top row and right clicked. 我不知道那是什么意思,所以我选择了第二行到第一行并单击鼠标右键。 It showed "Reset to master to this commit". 它显示“重置为掌握此提交”。 I attached screen shots. 我附上了屏幕截图。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

I just want to reverse all my local changes at this point. 我现在只想撤消所有本地更改。 Is this what I want to do? 这是我想做的吗?

In your second screenshot is a dropdown labeled "Using Mode" 在您的第二个屏幕截图中,有一个标记为“使用模式”的下拉菜单

If you do "Mixed" then everything you undo will be staged and ready to re-commit. 如果您进行“混合”操作,则撤消的所有操作都将上演并准备重新提交。 This is a safer way to reset. 这是更安全的重置方式。

Alternatively, if you do "hard" then all changes will be deleted as if they never happened. 或者,如果您进行“硬”操作,则所有更改都将被删除,就像从未发生过一样。 IT sounds like you want to do that. 听起来您想这样做。

Another thing to note, when you reset an earlier commit it resets everything from current head all the way back. 还要注意的另一件事是,当您重置较早的提交时,它将重置从当前头开始的所有内容。

After all of your work is done you'll need to do a force push. 完成所有工作后,您将需要进行推力操作。 This isn't supported by SourceTree so you'll need to click the "Console" button at the top of the SourceTree window then type: SourceTree不支持此功能,因此您需要单击SourceTree窗口顶部的“控制台”按钮,然后键入:

git push origin -f

WARNING - Don't do any of these steps if this is a team effort. 警告-如果这是团队合作,请勿执行任何这些步骤。 Other developers will run into issues. 其他开发人员将遇到问题。 This is true just about anytime you need to do a force push. 几乎在您需要进行推力的任何时候都是如此。

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

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