开发者

Git relative revision numbers

Is it possible (somehow) to have in Git (local) relative re开发者_如何学Cvision (commit) numbers, like in Mercurial 0, 1, 2, 3, ... instead of short hashes?

Or anything more user friendly?


Just use:

  • master~10 to 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.

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

master can be any branch name (local or remote) or HEAD to reference the current commit.

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


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 980e as long as no other commits start with 980e.


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

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

commit 4  id: a4d0892d38f4d72902e35a5b1ca11e602fffcef6

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

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.)

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 log breaks my flow. So I hope it will help both of us.


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 -a v1.2 HEAD

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜