Git:如何回滚/撤消对图像的更改?
因此我们的设计师对一些图像进行了一些更改,并提交了更改。所以现在我们的 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 1
和 Commit 2
中所做的更改覆盖新映像?
So our designer made some changes to some images, and committed the changes. So now our git log
looks something like this:
Commit 1: Changed images
Commit 2: Oops, forgot to commit a few images
...then the business wanted them to look different, so the designer changed them, and committed them again:
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
...now the business decided that they liked the images better the first time. So now we need to roll back to the way they were near the beginning. I have tried a few different approaches and I think the approach I need to use is git revert
so that I can create a new commit that reverts the images back to the way they were before. However, I seem to be having conflicts when I try to do this. How should I do this so that I can force the new images to be overwritten with the changes made in Commit 1
and Commit 2
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要做的是从旧提交中检出该文件。
它看起来像:
该提交引用规范可能是 HEAD{4} 或可能是 SHA 或可能是标签......引用该提交的东西。然后它将作为要添加和提交的更改位于您的工作目录中。
What you want to do is check the file out from an old commit.
It'll look like:
that commit refspec might be HEAD{4} or might be a SHA or maybe a tag.... Something that refers to that commit. Then it'll be sitting in your working directory as a change to add and commit.
如果这些都不是合并提交,则 git revert>应该可以解决问题(其中
是提交的 SHA1)。如果您有未提交的更改,请执行git stash
。或者,执行 git checkout-- <要恢复的图像的文件名> 后跟
git add
和提交。If none of these are merge commits, then
git revert <Commit 3> <Commit 4>
should do the trick (where<Commit X>
is the SHA1 of the commit). Do agit stash
if you have uncommitted changes.Alternatively, do
git checkout <Commit 2> -- <filenames of images to be restored>
followed bygit add
and a commit.