我如何取消提交git仓库中的最后一个提交?

编程入门 行业动态 更新时间:2024-10-10 14:30:16
本文介绍了我如何取消提交git仓库中的最后一个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 考虑到有几个git命令在裸存储库中没有意义(因为裸存储库不使用索引并且没有工作目录),

git reset --hard HEAD ^

不是一个解决方案,取消在这样一个存储库中的最后一次更改。

通过互联网搜索,我可以找到与该主题相关的所有内容这个,我在这里介绍了三种这样做的方法: 1.更新手动ref(涉及管道); 2. git push -f 从非裸仓库; 3. git branch -f this $ that 。

您认为哪种解决方案更适当的还是其他的方式来做到这一点?不幸的是,我发现有关git裸仓库的文档相当糟糕。

您可以使用 git update-ref 命令。要删除最后一次提交,您可以使用:

$ git update-ref HEAD HEAD ^ 或者如果你不在你不能从其中删除最后一次提交的分支:

$ git update-ref refs / heads / branch-name分支名称^

如果你愿意的话,你也可以传递一个sha1: $ p $ code $ git update-ref refs / heads / branch-name a12d48e2

请参阅 git-update-ref 命令。

Taking into consideration that there are several git commands that make no sense in a bare repository (because bare repositories don't use indexes and do not have a working directory),

git reset --hard HEAD^

is not a solution to uncommit the last change in such a repository.

Searching through the Internet, all I could find related to the topic is this, in which I am presented three ways of doing this: 1. "update the ref manually (which involves plumbing)"; 2. "git push -f from a non-bare repository"; 3. "git branch -f this $that".

Which solution do yo think is more appropriate or what other ways are there to do this? Unfortunately, the documentation I found about git bare repositories is fairly poor.

解决方案

You can use the git update-ref command. To remove the last commit, you would use:

$ git update-ref HEAD HEAD^

Or if you're not in the branch from which you cant to remove the last commit:

$ git update-ref refs/heads/branch-name branch-name^

You could also pass a sha1 if you want:

$ git update-ref refs/heads/branch-name a12d48e2

See the documentation of the git-update-ref command.

更多推荐

我如何取消提交git仓库中的最后一个提交?

本文发布于:2023-10-19 02:05:33,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:仓库   git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!