重置为Git中的第一次提交? [英] Reset to the very first commit in Git?

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

问题描述

rebase 命令中是否有相当于 - root 标志的重置命令?

  git reset --root 

假设我想重置为当前分支中的第一次提交:是否必须手动挖掘历史记录并查找该提交的散列,还是有一种简单的方法来重置第一个可用的提交?

解决方案

根提交(可以有多个)是一个没有父母的提交。



这会找到当前提交的根提交(基本上是当前分支的根目录,除非它可以使用分离的HEAD ):

  git rev-list --max-parents = 0 HEAD 

这会发现所有分支上的所有root提交:

  git rev-list --max-parents = 0 --branches 

当然你可以使用 - tags - 所有而不是 - 分支



通常,只有一个存储库中的根因此所有这些都会找到相同的版本,默认情况下, rev-list 以合适的顺序打印修订版,所以 manojlds'answer 通常也可以工作。

编辑:当然,您必须提供生成的SHA-1 git reset


Is there anything equivalent to the --root flag in the rebase command for the reset command?

git reset --root

Say I want to reset to the very first commit in my current branch: do I have to manually dig through the history and find the hash of that commit, or is there a simple way to reset to the first available commit?

解决方案

A root commit (there can be more than one) is a commit with no parents.

This finds the root commit of the current commit (basically, "root of current branch" except that it works even with a detached HEAD):

git rev-list --max-parents=0 HEAD

This finds all root commits on all branches:

git rev-list --max-parents=0 --branches

and of course you can use --tags or --all instead of --branches.

Usually there's only one root in a repository so that all of these find the same revision, and rev-list prints revisions in a suitable order by default, so manojlds' answer will generally also work.

Edit: and of course, you have to provide the resulting SHA-1 to git reset.

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

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