撤消git在文件上更改

发布于 2025-01-31 06:15:33 字数 279 浏览 3 评论 0原文

我做了几次投入并将它们推了下来,远程看起来像这样:

abcd ---...- n

commit b是4个修改后的文件(a,b,c,d)。我意识到我只想更改文件A,因此我需要丢弃B,C,D更改。问题在于我已经推动了该提交,并提出了更多的承诺。文件A在以后的提交中经常修改。 问题是当我单击Visual Studio 2022 =&GT时;管理分支=>还原,只有B和C文件更改已恢复,因此A和D仍然存在。我得到一个弹出窗口,说这是一个错误,但是输出窗口上没有什么。 问题是:如何使用git bash执行此操作?

I made several commits and pushed them so, remote looks like this:

A-B-C-D---...--N

Commit B is of 4 modified files (a, b, c, d). I realized that I only want changes in file a, so I need to discard b,c,d changes. The problem is that I have already pushed the commit and made more commits that I have pushed as well. File a has been modified a lot in later commits.
Problem is that when I click on Visual Studio 2022=> Manage branches => revert, only b and c file changes have been reverted, therefore a and d are still there. I get a pop up saying that it has been an error, but there is nothing on the output window.
Question is: how do I do this using git bash?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

国粹 2025-02-07 06:15:33

使用git bash,您可以找到提交的sha(使用GUI或git log),然后您只需启动git revert< sha>
这将创建一个新的提交,以恢复您在原始提交中所做的更改。

With git bash you find the sha of the commit (use a gui, or git log), then you simply launch git revert <SHA>
This will create a new commit that revert the changes you made in the original commit.

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