简体   繁体   English

GitHub转到上一个提交

[英]GitHub go to previous commit

I'm collaborating with a friend on a website and wanted to update something, but now we realize that we don't want the update. 我正在与一个网站上的朋友合作,想要更新某些东西,但是现在我们意识到我们不希望更新。 So I found the commit we need, and typed 所以我找到了我们需要的提交,然后输入

git reset --hard 0033e84…dffa6

because I found it on google, and this just replaced the changed file from back then. 因为我在google上找到了它,所以从那时开始就替换了更改过的文件。 We want every file from back then, not just one. 从那时起,我们希望每个文件,而不仅仅是一个。 Then again I typed 然后我再次输入

git revert 0033e84…dffa6

and now somehow the "Last update" on the files changed, but the content is still the same new we don't want. 现在文件上的“最新更新”有所更改,但是内容仍然是我们不希望的新内容。 We just want to go back. 我们只想回去。 Why is that so confusing? 为什么这么混乱?

I only found those two command to go back, and it didn't help. 我只发现这两个命令可以返回,但并没有帮助。 The problem now is that the old commits are overwritten and its just messy. 现在的问题是,旧的提交被覆盖,而且只是一团糟。

What's the correct command to just go back in time with all the files and stuff? 回到所有文件和内容的正确命令是什么? As it was before, not just some files. 和以前一样,不仅仅是一些文件。

The possible dublicate does not work in case of my problem. 如果出现我的问题,可能的重复操作不起作用。 Whenever I want to go back, it just changes the commited FILE, not FILES in between. 每当我想返回时,它只会更改已提交的文件,而不是两者之间的文件。

Say, your branch name is b1 . 假设您的分支名称为b1 Then try: 然后尝试:

$ git checkout b1

# revert the commits changes
$ git revert <from-commit-hash>..<to-commit-hash>

If you typed 如果您输入

$ git reset --hard 0033e84…dffa6

all your file change between HEAD and this commit will back to this commit, and commit record will be discarded. 在HEAD与该提交之间的所有文件更改都将返回到该提交,并且提交记录将被丢弃。

If you typed 如果您输入

$ git revert 0033e84…dffa6

a new commit will be created to revert the change in commit 0033e84…dffa6 将创建一个新的提交以还原提交0033e84…dffa6中的更改

As you described,I think the first command is what you need, only the files add in repository will be back, only the files change between HEAD and this commit will change. 正如您所描述的,我认为第一个命令就是您所需要的,只会返回存储库中添加的文件,只会在HEAD之间更改文件,并且此提交也会更改。

Now what I did is a new branch, then I 现在我做了一个新的分支,然后我

git reset --hard 1b2d6cb9857420892b120fcc67f528ed68435599

And it told me "HEAD is now at 1b2d6cb Commit Message " Now I was excited, because Terminal told me there is a folder, that belonged to the old version we wanted, called panel 它告诉我“ HEAD现在位于1b2d6cb 提交消息 ”现在,我很兴奋,因为Terminal告诉我有一个文件夹,该文件夹属于我们想要的旧版本,称为面板

Then I checked in my Finder, there was no folder called panel 然后我在Finder中签入,没有名为panel的文件夹

I checked again in the Terminal via ls, and its gone again! 我通过ls在终端中再次检查,然后又消失了! I feel like I am using the computer for the first time. 我觉得我是第一次使用电脑。 What is going on. 到底是怎么回事。 Here a screenshot: 这里的截图:

Terminal Screenshot 终端截图

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

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