简体   繁体   English

将存储库恢复为特定提交,而不会丢失其间所做的更改

[英]Revert repositiory to specific commit without loosing changes made in the meantime

I need the state of my repository at a specific commit/date. 我需要特定提交/日期的存储库状态。 I don't want to revert back, because I don't want to loose my changes. 我不想退回,因为我不想放弃更改。

How can I get the repository at a specific commit? 如何在特定提交时获取存储库?

I made a research and perhaps the following would work: 我进行了研究,也许以下方法会起作用:

git log
git clone /path/to/repository
git checkout dec5f4de67ff32fd ...

Do I get some side-effects between the cloned and the origin repository? 在克隆的存储库和原始存储库之间是否有一些副作用? Do I have all commits available in my cloned repository? 我的克隆存储库中是否有所有可用的提交? How can I delete the cloned repository? 如何删除克隆的存储库? Simply deleting the folder? 只是删除文件夹? I don't want a new branch - I only need the project at a specific commit. 我不需要新的分支-我只需要在特定提交时执行项目。

Edit: 编辑:

Now I tried git checkout xxx . 现在我尝试了git checkout xxx It worked. 有效。 Then I wanted to get back to my latest changes with git checkout master . 然后,我想回到git checkout master最新更改。 I got the following error 我收到以下错误

error: The following untracked working tree files would be overwritten by checkout: 错误:以下未跟踪的工作树文件将被签出覆盖:
Project/Resources/image.png 项目/资源/image.png
Please move or remove them 请移动或删除它们
before you can switch branches. 在切换分支之前。 Aborting 堕胎

The reason was that I checked out the wrong branch (not master). 原因是我签出了错误的分支(不是主分支)。 Now I deleted all files and used the one from a backup. 现在,我删除了所有文件,并从备份中使用了其中一个文件。 If I now enter git log he only shows me the initial commit ... So I moved out of the folder with the console and back in and now he shows me the latest commits. 如果我现在输入git log他只会显示我的初始提交...因此,我使用控制台从文件夹中移出并返回,现在他显示了最新的提交。

So be aware of what you checkout. 因此,请注意您结帐的内容。

You want a copy of your repository as it was before commits? 您想要提交之前的存储库副本吗? The clone will have all the commits from your original. 克隆将包含原始副本中的所有提交。 If you want to get rid of the latest commits in the clone you have to use: 如果要摆脱克隆中的最新提交,则必须使用:

git clone /path/to/repository
git reset --hard dec5f4de67ff32fd ...

if you just checkout the commit then the newer commits are still there in the repository, only the work space will be changed to the previous commit. 如果仅签出提交,则较新的提交仍在存储库中,只有工作空间将更改为先前的提交。

More detail: https://stackoverflow.com/a/4114122/4809302 更多详细信息: https : //stackoverflow.com/a/4114122/4809302

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

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