{"thread":{"id":"49949","subject":"Any way to make git-log to enumerate commits?","startedAt":"2018-12-05T14:28:12Z","lastAt":"2018-12-07T00:12:35Z","messageCount":7,"participants":["Konstantin Kharlamov","Konstantin Khomoutov","Elijah Newren","Andreas Schwab","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"364625","messageId":"5e5c6d1c-6b3e-c94a-17be-a2af518c1607@yandex.ru","threadId":"49949","inReplyTo":null,"subject":"Any way to make git-log to enumerate commits?","fromName":"Konstantin Kharlamov","fromEmail":"hi-angel@yandex.ru","sentAt":"2018-12-05T14:22:14Z","receivedAt":"2018-12-05T14:28:12Z","isPatch":false,"sender":{"key":"hi-angel@yandex.ru","avatar":null},"body":"It would be great if git-log has a formatting option to insert an index of the current commit since HEAD.\n\nIt would allow after quitting the git-log to immediately fire up \"git rebase -i HEAD~index\" instead of \"git rebase -i go-copy-paste-this-long-number-id\".\n"},{"id":"364627","messageId":"20181205145419.vbbaghzzrnceez45@tigra","threadId":"49949","inReplyTo":"5e5c6d1c-6b3e-c94a-17be-a2af518c1607@yandex.ru","subject":"Re: Any way to make git-log to enumerate commits?","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2018-12-05T14:54:20Z","receivedAt":"2018-12-05T14:54:28Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:\n\n> It would be great if git-log has a formatting option to insert an\n> index of the current commit since HEAD.\n> \n> It would allow after quitting the git-log to immediately fire up \"git\n> rebase -i HEAD~index\" instead of \"git rebase -i\n> go-copy-paste-this-long-number-id\".\n\nThis may have little sense in a general case as the history maintained\nby Git is a graph, not a single line. Hence your prospective approach\nwould only work for cases like `git log` called with the\n\"--first-parent\" command-line option.\n\nStill, for a simple approach you may code it right away yourself.\nSay, let's create an alias:\n\n  $ git config alias.foo '!git log \"$@\" --pretty=oneline --source | {\n      n=0;\n      while read sha ref rest; do\n        printf \"%s\\t%s~%s\\t%s\\n\" \"$sha\" \"$ref\" $n \"$rest\"\n\t\tn=$((n+1))\n\t  done\n    }'\n\nNow calling `git foo --abbrev=commit` would output something like\n\n9be8e297d        HEAD~7       Frobincated fizzle\n\nwhere \"7\" is what you're looking for.\n\nA more roubst solution may need to use the `git rev-list` command.\n\n"},{"id":"364628","messageId":"CABPp-BHhYgBndaOjTC9-YQ5gNJXqaw21Hf=FZzyA7AKDQvN+0A@mail.gmail.com","threadId":"49949","inReplyTo":"20181205145419.vbbaghzzrnceez45@tigra","subject":"Re: Any way to make git-log to enumerate commits?","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-12-05T15:31:45Z","receivedAt":"2018-12-05T15:31:59Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Wed, Dec 5, 2018 at 6:56 AM Konstantin Khomoutov <kostix@bswap.ru> wrote:\n>\n> On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:\n>\n> > It would be great if git-log has a formatting option to insert an\n> > index of the current commit since HEAD.\n> >\n> > It would allow after quitting the git-log to immediately fire up \"git\n> > rebase -i HEAD~index\" instead of \"git rebase -i\n> > go-copy-paste-this-long-number-id\".\n>\n> This may have little sense in a general case as the history maintained\n> by Git is a graph, not a single line. Hence your prospective approach\n> would only work for cases like `git log` called with the\n> \"--first-parent\" command-line option.\n>\n> Still, for a simple approach you may code it right away yourself.\n> Say, let's create an alias:\n>\n>   $ git config alias.foo '!git log \"$@\" --pretty=oneline --source | {\n>       n=0;\n>       while read sha ref rest; do\n>         printf \"%s\\t%s~%s\\t%s\\n\" \"$sha\" \"$ref\" $n \"$rest\"\n>                 n=$((n+1))\n>           done\n>     }'\n>\n> Now calling `git foo --abbrev=commit` would output something like\n>\n> 9be8e297d        HEAD~7       Frobincated fizzle\n>\n> where \"7\" is what you're looking for.\n>\n> A more roubst solution may need to use the `git rev-list` command.\n\nOr, just use name-rev so it works with non-linear histories too:\n\ngit log | git name-rev --refs=$(git symbolic-ref HEAD) --stdin | less\n\nThat'll add things like \"master~7\" for stuff in the first parent\nhistory and output like \"master~7^2~3\" for commits on side-branches,\neither of which can be fed to other git commands.\n"},{"id":"364630","messageId":"87sgzcyo6x.fsf@igel.home","threadId":"49949","inReplyTo":"CABPp-BHhYgBndaOjTC9-YQ5gNJXqaw21Hf=FZzyA7AKDQvN+0A@mail.gmail.com","subject":"Re: Any way to make git-log to enumerate commits?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2018-12-05T15:43:02Z","receivedAt":"2018-12-05T15:43:06Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Dez 05 2018, Elijah Newren <newren@gmail.com> wrote:\n\n> Or, just use name-rev so it works with non-linear histories too:\n>\n> git log | git name-rev --refs=$(git symbolic-ref HEAD) --stdin | less\n\nThat wouldn't work for a detached HEAD, though, and you need to use\n--no-abbrev.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"364662","messageId":"xmqqa7ljbimv.fsf@gitster-ct.c.googlers.com","threadId":"49949","inReplyTo":"20181205145419.vbbaghzzrnceez45@tigra","subject":"Re: Any way to make git-log to enumerate commits?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-06T00:31:36Z","receivedAt":"2018-12-06T00:31:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Konstantin Khomoutov <kostix@bswap.ru> writes:\n\n> On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:\n>\n>> It would be great if git-log has a formatting option to insert an\n>> index of the current commit since HEAD.\n>> \n>> It would allow after quitting the git-log to immediately fire up \"git\n>> rebase -i HEAD~index\" instead of \"git rebase -i\n>> go-copy-paste-this-long-number-id\".\n>\n> This may have little sense in a general case as the history maintained\n> by Git is a graph, not a single line. Hence your prospective approach\n> would only work for cases like `git log` called with the\n> \"--first-parent\" command-line option.\n\nI do not see why the \"name each rev relative to HEAD\" formatting\noption cannot produce HEAD^2~2 etc.\n\nIt would be similar to \"git log | git name-rev --stdin\" but I do not\noffhand recall if we had a way to tell name-rev to use only HEAD as\nthe anchoring point.\n"},{"id":"364681","messageId":"20181206114835.oro32chgf4qp2yqd@tigra","threadId":"49949","inReplyTo":"xmqqa7ljbimv.fsf@gitster-ct.c.googlers.com","subject":"Re: Any way to make git-log to enumerate commits?","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2018-12-06T11:48:36Z","receivedAt":"2018-12-06T11:48:45Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Thu, Dec 06, 2018 at 09:31:36AM +0900, Junio C Hamano wrote:\n\n> >> It would be great if git-log has a formatting option to insert an\n> >> index of the current commit since HEAD.\n> >> \n> >> It would allow after quitting the git-log to immediately fire up \"git\n> >> rebase -i HEAD~index\" instead of \"git rebase -i\n> >> go-copy-paste-this-long-number-id\".\n> >\n> > This may have little sense in a general case as the history maintained\n> > by Git is a graph, not a single line. Hence your prospective approach\n> > would only work for cases like `git log` called with the\n> > \"--first-parent\" command-line option.\n> \n> I do not see why the \"name each rev relative to HEAD\" formatting\n> option cannot produce HEAD^2~2 etc.\n> \n> It would be similar to \"git log | git name-rev --stdin\" but I do not\n> offhand recall if we had a way to tell name-rev to use only HEAD as\n> the anchoring point.\n\nMy reading was that the OP explicitly wanted to just glance at a single\ninteger number and use it right away in a subsequent rebase command.\n\nI mean, use one's own short memory instead of copying and pasting.\n\nThe way I decided to format the reference in my sketch script — using\nHEAD~<n> — is just a byproduct of the fact I was aware both of the\n\"gitrevisions\" manual page and the fact `git name-rev` exists (though I\nregretfully was not aware it's able to process a stream of `git log`).\n\nHence while getting fancy names for revisions would be technically\ncorrect but less error-prone for retyping from memory ;-)\n\n"},{"id":"364726","messageId":"xmqqr2eu8aaa.fsf@gitster-ct.c.googlers.com","threadId":"49949","inReplyTo":"20181206114835.oro32chgf4qp2yqd@tigra","subject":"Re: Any way to make git-log to enumerate commits?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-07T00:12:29Z","receivedAt":"2018-12-07T00:12:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Konstantin Khomoutov <kostix@bswap.ru> writes:\n\n>> I do not see why the \"name each rev relative to HEAD\" formatting\n>> option cannot produce HEAD^2~2 etc.\n>>  ...\n> My reading was that the OP explicitly wanted to just glance at a single\n> integer number and use it right away in a subsequent rebase command.\n>\n> I mean, use one's own short memory instead of copying and pasting.\n\nAs everybody pointed out, a single integer number will fundamentally\nunworkable with distributed nature of Git that inherently makes the\nhistory with forks and merges.  Besides, there is no way to feed\n\"git log\" with \"a single integer number\", without which \"making\ngit-log to enumerate\" would not be all that useful (\"git show\nHEAD~4\" works but \"git show 4\" does not).\n\nAll of these name-rev based suggestions were about using anchoring\npoint with memorable name plus a short path to reach from there,\nwhich I think is the closest thing to \"a single integer number\" and\nstill is usable for the exact purpose.  \"HEAD~48^2\" on an\nintegration branch would be \"the tip of the side branch that was\nmerged some 48 commits ago\", for example.\n"}]}