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.
我有一个需要在存储库中引用初始提交的脚本。 git有特殊参考HEAD,但没有相应的TAIL。我无法在git help rev-parse中找到任何对我有帮助的东西。
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.
这非常hacky,取决于git log的输出不变。
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.
现在我只标记初始提交并将其用作我的refspec。但是,我想发布一个通用工具,所以这不是一个很好的选择。
2 个解决方案
#1
Do not use git-log for scripting: use either git-rev-list, or git-log with specified custom format ("--format=<sth>" option).
不要使用git-log进行脚本编写:使用git-rev-list或git-log和指定的自定义格式(“--format =
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.
您的问题还有一个问题:存储库中可能存在多个这样的TAIL根提交(无父提交)(即使我们在git.git中对断开的分支进行折扣,例如'html','man'和'todo'库)。这通常是将单独的项目合并为一个或使用单独开发的子项目的子树合并的结果。
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.
例如,git存储库有6个root提交:git-gui,gitk(子树合并),gitweb(合并,不再单独开发),git mail工具(在项目历史的早期合并)和p4-fast-export(也许意外)。这不包括'html和'man'分支的根源,包含预生成文档的“便利”分支,以及包含TODO列表和脚本的“todo”分支。
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 1.7.4.2或更新版本,你可以使用新的--max-parents选项:
$ git rev-list --max-parents=0 HEAD
#2
git rev-list HEAD | tail -n 1
is a more stable option.
git rev-list HEAD | tail -n 1是一个更稳定的选择。
#1
Do not use git-log for scripting: use either git-rev-list, or git-log with specified custom format ("--format=<sth>" option).
不要使用git-log进行脚本编写:使用git-rev-list或git-log和指定的自定义格式(“--format =
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.
您的问题还有一个问题:存储库中可能存在多个这样的TAIL根提交(无父提交)(即使我们在git.git中对断开的分支进行折扣,例如'html','man'和'todo'库)。这通常是将单独的项目合并为一个或使用单独开发的子项目的子树合并的结果。
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.
例如,git存储库有6个root提交:git-gui,gitk(子树合并),gitweb(合并,不再单独开发),git mail工具(在项目历史的早期合并)和p4-fast-export(也许意外)。这不包括'html和'man'分支的根源,包含预生成文档的“便利”分支,以及包含TODO列表和脚本的“todo”分支。
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 1.7.4.2或更新版本,你可以使用新的--max-parents选项:
$ git rev-list --max-parents=0 HEAD
#2
git rev-list HEAD | tail -n 1
is a more stable option.
git rev-list HEAD | tail -n 1是一个更稳定的选择。