Git:如何回滚/撤消对图像的更改?

发布于 2024-11-17 13:15:08 字数 593 浏览 2 评论 0原文

因此我们的设计师对一些图像进行了一些更改,并提交了更改。所以现在我们的 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 中所做的更改覆盖新映像?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-11-24 13:15:08

您想要做的是从旧提交中检出该文件。

它看起来像:

git checkout <commit 1 refspec> imagefilename.png

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

What you want to do is check the file out from an old commit.

It'll look like:

git checkout <commit 1 refspec> imagefilename.png

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.

预谋 2024-11-24 13:15:08

如果这些都不是合并提交,则 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 a git stash if you have uncommitted changes.

Alternatively, do git checkout <Commit 2> -- <filenames of images to be restored> followed by git add and a commit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文