如何引用最初的提交? [英] How to reference the initial commit?

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

问题描述

我有一个脚本需要引用存储库中的初始提交。 git有特殊的引用 HEAD ,但没有相应的 TAIL 。我无法在 git help rev-parse 中找到任何可以帮助我的东西。



这就是我想要的喜欢做:

  git show TAIL 

这里有一个选项:

  git show`git log --reverse |如果读取提交;然后echo $ commit; 

这很不方便,并且取决于git log的输出不变。



现在我只标记初始提交并将其用作我的refspec。不过,我想发布一个通用工具,所以这不是一个好选择。 不要使用git-log对于脚本:使用git-rev-list或git-log指定的自定义格式(--format = < sth> 选项)。

您的问题存在其他问题:在存储库中可能存在多个这样的TAIL根提交(无父提交)(即使我们打折断开连接的分支,如'html' ,'man'和'todo'在git.git仓库中)。这通常是将单独的项目合并为一个,或者使用单独开发的子项目的子树合并的结果。

例如git仓库有6个根提交:git-gui,gitk(子树合并),gitweb(合并,不再单独开发),git邮件工具在项目历史中很早就合并了),以及p4-fast-export(可能是偶然的)。这不包括'html和'man'分支的根源,包含预生成文档的便利分支以及包含TODO列表和脚本的'todo'分支。 $ b

您可以使用以下命令获取从当前分支可访问的所有无父级(根)提交的列表:

  $ git rev-list --parents HEAD | egrep^ [a-f0-9] {40} $

如果你有git 1.7。 4.2或更新版本,您可以使用新的 - max-parents 选项:

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


I've got a script that needs to reference the initial commit in a repository. git has the special reference HEAD, but doesn't have the corresponding TAIL. I cannot find anything in git help rev-parse that would seem to help me.

Here's what I'd like to do:

git show TAIL

Here's one option I have:

git show `git log --reverse | if read a commit ; then echo $commit ; fi`

That's pretty hacky and depends on the output of git log not changing.

Right now I just tag the initial commit and use that as my refspec. However, I'd like to release a general tool, so that's not a great option.

解决方案

Do not use git-log for scripting: use either git-rev-list, or git-log with specified custom format ("--format=<sth>" option).

There is additional problem with your question: there can exist more than one such TAIL root commit (parentless commit) in a repository (even if we discount disconnected branches, such as 'html', 'man' and 'todo' in git.git repository). This is usually result of joining separate projects in one, or using subtree merge of separately developed subproject.

For example git repository has 6 root commits: git-gui, gitk (subtree-merged), gitweb (merged in, no longer developed separately), git mail tools (merged very early in project history), and p4-fast-export (perhaps accidental). That is not counting roots of 'html and 'man' branches, "convenience" branches which contains pre-generated documentation, and 'todo' branch with TODO list and scripts.


You can get list of all parentless (root) commits accessible from current branch using:

$ git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"

If you have git 1.7.4.2 or newer, you can use the new --max-parents option:

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

这篇关于如何引用最初的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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