【问题标题】:Git: How to rollback/undo a change to an image?Git:如何回滚/撤消对图像的更改?
【发布时间】:2011-09-23 19:21:37
【问题描述】:

所以我们的设计师对一些图像进行了一些更改,并提交了这些更改。所以现在我们的git log 看起来像这样:

Commit 1: Changed images
Commit 2: Oops, forgot to commit a few images

...然后企业希望它们看起来不同,因此设计师更改了它们,并再次提交:

Commit 1: Changed images
Commit 2: Oops, forgot to commit a few images
Commit 3: Changed images again
Commit 4: Minor tweaks to new images just committed

...现在企业决定他们第一次更喜欢这些图像。所以现在我们需要回滚到它们接近开始的方式。我尝试了几种不同的方法,我认为我需要使用的方法是git revert,这样我就可以创建一个新的提交,将图像恢复到以前的样子。但是,当我尝试这样做时,我似乎遇到了冲突。我该怎么做才能强制用Commit 1Commit 2 中所做的更改覆盖新图像?

【问题讨论】:

    标签: git git-revert


    【解决方案1】:

    您要做的是从旧提交中检查文件。

    看起来像:

    git checkout <commit 1 refspec> imagefilename.png
    

    提交 refspec 可能是 HEAD{4} 或者可能是 SHA 或者可能是标签.... 引用该提交的东西。然后它将作为添加和提交的更改放在您的工作目录中。

    【讨论】:

      【解决方案2】:

      如果这些都不是合并提交,那么 git revert &lt;Commit 3&gt; &lt;Commit 4&gt; 应该可以解决问题(其中 &lt;Commit X&gt; 是提交的 SHA1)。如果您有未提交的更改,请发送git stash

      或者,执行git checkout &lt;Commit 2&gt; -- &lt;filenames of images to be restored&gt;,然后执行git add 和提交。

      【讨论】:

        猜你喜欢
        • 2021-09-30
        • 2019-10-12
        • 2013-03-11
        • 2016-12-07
        • 2015-01-30
        • 2021-02-17
        • 1970-01-01
        • 1970-01-01
        • 2010-09-26
        相关资源
        最近更新 更多