我如何取消提交git仓库中的最后一个提交? [英] How can I uncommit the last commit in a git bare repository?

查看:108
本文介绍了我如何取消提交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仓库中的最后一个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆