Git 相对修订号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5128866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:07:14  来源:igfitidea点击:

Git relative revision numbers

git

提问by Rook

Is it possible (somehow) to have in Git (local) relative revision (commit) numbers, like in Mercurial 0, 1, 2, 3, ... instead of short hashes?

是否有可能(以某种方式)在 Git(本地)中使用相对修订(提交)编号,例如 Mercurial 0、1、2、3……而不是短散列?

Or anything more user friendly?

或者更用户友好的东西?

回答by knittl

Just use:

只需使用:

  • master~10to get the 10th last commit on branch master.
  • master^to get the second last commit on branch master.
  • master^^to get the third last commit on branch master.
  • master~10在 branch 上获得第 10 次最后一次提交master
  • master^在 branch 上获得第二个最后一次提交master
  • master^^在 branch 上获得倒数第三次提交master

They can even be combined: master^^~5^.

它们甚至可以组合:master^^~5^.

mastercan be any branch name (local or remote) or HEADto reference the current commit.

master可以是任何分支名称(本地或远程)或HEAD引用当前提交。

You can use master^2to get the second merge parent.

您可以使用master^2来获取第二个合并父项。

回答by Aasmund Eldhuset

You can always refer to a commit by using a prefix of its SHA-1 hash, as long as it is unique. E.g., if you want to checkout 980e3ccdaac54a0d4de358f3fe5d718027d96aae, you can use git checkout 980eas long as no other commits start with 980e.

您始终可以通过使用其 SHA-1 哈希的前缀来引用提交,只要它是唯一的。例如,如果您想 checkout 980e3ccdaac54a0d4de358f3fe5d718027d96aaegit checkout 980e只要没有其他提交以 开头,您就可以使用980e

回答by James Jensen

I just made something doing exactly this: dash-r. It's still rough, but you might find it useful.

我刚刚做了一些事情:dash-r。它仍然很粗糙,但你可能会发现它很有用。

Basically, it's a shim that can produce a modified version of the basic git log with commit lines like so:

基本上,它是一个 shim,可以生成基本 git 日志的修改版本,其中包含如下提交行:

commit 4  id: a4d0892d38f4d72902e35a5b1ca11e602fffcef6

and then reference these numbers by surrounding the -rinvocation with backticks:

然后通过-r用反引号将调用括起来来引用这些数字:

git diff `-r 2`

(Assuming you install it in your path with the name "-r". I do that since it looks like a regular option if I ignore the backticks.)

(假设您将它安装在名为“-r”的路径中。我这样做是因为如果我忽略反引号,它看起来像是一个常规选项。)

It can even handle ranges and negative numbers:

它甚至可以处理范围和负数:

git diff `-r 2..-2`

Git's lack of revision numbers has been a major hurdle for me in warming to Git. Seeing SHA hashes in git logbreaks my flow. So I hope it will help both of us.

Git 缺少修订号一直是我开始使用 Git 的主要障碍。看到 SHA 哈希git log打破了我的流程。所以我希望它对我们俩都有帮助。

回答by Martin Olsen

Short answer: No.Yes.

简短回答:是的

However, you could use git-tag. For example, to tag your latest commit as version 1.2 do something like:

但是,您可以使用 git-tag。例如,要将最新提交标记为 1.2 版,请执行以下操作:

git tag -a v1.2 HEAD

This page explains how to use it for versioning: http://grinninggecko.com/commit-version-numbers-with-git/

此页面解释了如何使用它进行版本控制:http: //grinninggecko.com/commit-version-numbers-with-git/