如何删除git中的第一次提交? [英] How to remove the first commit in git?

查看:676
本文介绍了如何删除git中的第一次提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇如何在git中删除第一次提交。



在提交任何东西前的修订是什么?这个版本有一个名字或标签吗?

解决方案

对我而言,最安全的方法是使用 update-ref 命令:

  git update-ref -d HEAD 
code>

它将删除指定的引用 HEAD ,所以它会重置(轻轻松松,不会失去工作)当前分支的所有提交

如果您想要将第一次提交与第二个,你可以使用 rebase 命令:

  git rebase  - 我 - 根

最后一种方法是创建一个孤立分支,一个分支具有相同的内容但没有任何提交历史记录,并提交您的新内容:

  git checkout --orphan< new-branch-name> ; 


I am curious about how to remove the first commit in git.

What is the revision before committing any thing? Does this revision have a name or tag?

解决方案

For me, the most secure way is to use the update-ref command:

git update-ref -d HEAD

It will delete the named reference HEAD, so it will reset (softly, you will not lose your work) all your commits of your current branch.

If what you want is to merge the first commit with the second one, you can use the rebase command:

git rebase -i --root

A last way could be to create an orphan branch, a branch with the same content but without any commit history, and commit your new content on it:

git checkout --orphan <new-branch-name>

这篇关于如何删除git中的第一次提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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