使用Git恢复基于commit id的特定提交? [英] Reverting to a specific commit based on commit id with Git?

查看:277
本文介绍了使用Git恢复基于commit id的特定提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 git log ,我得到了迄今为​​止提交的提交列表。

 提交f5c5cac0033439c17ebf905d4391dc0705dbd5f1 
作者:prosseek
日期:星期五9月3日14:36:59 2010 -0500

添加并修改了文件。

提交c14809fafb08b9e96ff2879999ba8c807d10fb07
作者:prosseek
日期:星期二8月31日08:59:32 2010 -0500

只需简单测试core.editor。

...等...




  • 我如何将它恢复为特定的提交?例如,如果我想回到 commit c14809fafb08b9e96ff2879999ba8c807d10fb07


  • 任何其他/更好的方式回到与Git的具体提交?例如,我可以在每个提交的标签上加上标签吗?



解决方案

您是否想要将回购回滚到该状态?或者你只是想让你的本地回购看起来像这样?



如果你这样做

  git reset --hard c14809fa 

这会使您的本地代码和本地历史记录变得简单就像它在那个承诺一样。但是如果你想把它推给别人谁有新的历史,它会失败。



如果你这样做

  git reset --soft c14809fa 

让你的本地文件变得像他们那样,但留下你的历史等等。



所以你想要做这个重设?

编辑 -



您可以将标签添加到回购库中,然后返回标签。但标签实际上只是sha1的捷径。

您可以将其标记为TAG1 ..然后将 git reset --soft c14809fa git reset --soft TAG1 git reset --soft c14809fafb08b9e96ff2879999ba8c807d10fb07 都会做同样的事情。


With git log, I get a list of commits that I have made so far.

commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1
Author: prosseek 
Date:   Fri Sep 3 14:36:59 2010 -0500

    Added and modified the files.

commit c14809fafb08b9e96ff2879999ba8c807d10fb07
Author: prosseek 
Date:   Tue Aug 31 08:59:32 2010 -0500

    Just simple test for core.editor.

... etc ...

  • How can I revert it back to a specific commit? For example, what should I do if I want to go back to commit c14809fafb08b9e96ff2879999ba8c807d10fb07?

  • Is there any other/better way to go back to a specific commit with Git? For example, can I put some label of each commit to get it back with the label?

解决方案

Do you want to roll back your repo to that state? Or you just want your local repo to look like that?

if you do

git reset --hard c14809fa

It will make your local code and local history be just like it was at that commit. But then if you wanted to push this to someone else who has the new history, it would fail.

if you do

git reset --soft c14809fa

It will make your local files changed to be like they were then, but leave your history etc. the same.

So what exactly do you want to do with this reset?

Edit -

You can add "tags" to your repo.. and then go back to a tag. But a tag is really just a shortcut to the sha1.

You can tag this as TAG1.. then a git reset --soft c14809fa, git reset --soft TAG1, or git reset --soft c14809fafb08b9e96ff2879999ba8c807d10fb07 would all do the same thing.

这篇关于使用Git恢复基于commit id的特定提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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