git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Any way to make git-log to enumerate commits?
@ 2018-12-05 14:22 Konstantin Kharlamov
  2018-12-05 14:54 ` Konstantin Khomoutov
  0 siblings, 1 reply; 7+ messages in thread
From: Konstantin Kharlamov @ 2018-12-05 14:22 UTC (permalink / raw)
  To: git

It would be great if git-log has a formatting option to insert an index of the current commit since HEAD.

It 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".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Any way to make git-log to enumerate commits?
  2018-12-05 14:22 Any way to make git-log to enumerate commits? Konstantin Kharlamov
@ 2018-12-05 14:54 ` Konstantin Khomoutov
  2018-12-05 15:31   ` Elijah Newren
  2018-12-06  0:31   ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Konstantin Khomoutov @ 2018-12-05 14:54 UTC (permalink / raw)
  To: Konstantin Kharlamov; +Cc: git

On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:

> It would be great if git-log has a formatting option to insert an
> index of the current commit since HEAD.
> 
> It 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".

This may have little sense in a general case as the history maintained
by Git is a graph, not a single line. Hence your prospective approach
would only work for cases like `git log` called with the
"--first-parent" command-line option.

Still, for a simple approach you may code it right away yourself.
Say, let's create an alias:

  $ git config alias.foo '!git log "$@" --pretty=oneline --source | {
      n=0;
      while read sha ref rest; do
        printf "%s\t%s~%s\t%s\n" "$sha" "$ref" $n "$rest"
		n=$((n+1))
	  done
    }'

Now calling `git foo --abbrev=commit` would output something like

9be8e297d        HEAD~7       Frobincated fizzle

where "7" is what you're looking for.

A more roubst solution may need to use the `git rev-list` command.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Any way to make git-log to enumerate commits?
  2018-12-05 14:54 ` Konstantin Khomoutov
@ 2018-12-05 15:31   ` Elijah Newren
  2018-12-05 15:43     ` Andreas Schwab
  2018-12-06  0:31   ` Junio C Hamano
  1 sibling, 1 reply; 7+ messages in thread
From: Elijah Newren @ 2018-12-05 15:31 UTC (permalink / raw)
  To: kostix; +Cc: hi-angel, Git Mailing List

On Wed, Dec 5, 2018 at 6:56 AM Konstantin Khomoutov <kostix@bswap.ru> wrote:
>
> On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:
>
> > It would be great if git-log has a formatting option to insert an
> > index of the current commit since HEAD.
> >
> > It 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".
>
> This may have little sense in a general case as the history maintained
> by Git is a graph, not a single line. Hence your prospective approach
> would only work for cases like `git log` called with the
> "--first-parent" command-line option.
>
> Still, for a simple approach you may code it right away yourself.
> Say, let's create an alias:
>
>   $ git config alias.foo '!git log "$@" --pretty=oneline --source | {
>       n=0;
>       while read sha ref rest; do
>         printf "%s\t%s~%s\t%s\n" "$sha" "$ref" $n "$rest"
>                 n=$((n+1))
>           done
>     }'
>
> Now calling `git foo --abbrev=commit` would output something like
>
> 9be8e297d        HEAD~7       Frobincated fizzle
>
> where "7" is what you're looking for.
>
> A more roubst solution may need to use the `git rev-list` command.

Or, just use name-rev so it works with non-linear histories too:

git log | git name-rev --refs=$(git symbolic-ref HEAD) --stdin | less

That'll add things like "master~7" for stuff in the first parent
history and output like "master~7^2~3" for commits on side-branches,
either of which can be fed to other git commands.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Any way to make git-log to enumerate commits?
  2018-12-05 15:31   ` Elijah Newren
@ 2018-12-05 15:43     ` Andreas Schwab
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2018-12-05 15:43 UTC (permalink / raw)
  To: Elijah Newren; +Cc: kostix, hi-angel, Git Mailing List

On Dez 05 2018, Elijah Newren <newren@gmail.com> wrote:

> Or, just use name-rev so it works with non-linear histories too:
>
> git log | git name-rev --refs=$(git symbolic-ref HEAD) --stdin | less

That wouldn't work for a detached HEAD, though, and you need to use
--no-abbrev.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Any way to make git-log to enumerate commits?
  2018-12-05 14:54 ` Konstantin Khomoutov
  2018-12-05 15:31   ` Elijah Newren
@ 2018-12-06  0:31   ` Junio C Hamano
  2018-12-06 11:48     ` Konstantin Khomoutov
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2018-12-06  0:31 UTC (permalink / raw)
  To: Konstantin Khomoutov; +Cc: Konstantin Kharlamov, git

Konstantin Khomoutov <kostix@bswap.ru> writes:

> On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:
>
>> It would be great if git-log has a formatting option to insert an
>> index of the current commit since HEAD.
>> 
>> It 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".
>
> This may have little sense in a general case as the history maintained
> by Git is a graph, not a single line. Hence your prospective approach
> would only work for cases like `git log` called with the
> "--first-parent" command-line option.

I do not see why the "name each rev relative to HEAD" formatting
option cannot produce HEAD^2~2 etc.

It would be similar to "git log | git name-rev --stdin" but I do not
offhand recall if we had a way to tell name-rev to use only HEAD as
the anchoring point.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Any way to make git-log to enumerate commits?
  2018-12-06  0:31   ` Junio C Hamano
@ 2018-12-06 11:48     ` Konstantin Khomoutov
  2018-12-07  0:12       ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Konstantin Khomoutov @ 2018-12-06 11:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Konstantin Khomoutov, Konstantin Kharlamov, git

On Thu, Dec 06, 2018 at 09:31:36AM +0900, Junio C Hamano wrote:

> >> It would be great if git-log has a formatting option to insert an
> >> index of the current commit since HEAD.
> >> 
> >> It 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".
> >
> > This may have little sense in a general case as the history maintained
> > by Git is a graph, not a single line. Hence your prospective approach
> > would only work for cases like `git log` called with the
> > "--first-parent" command-line option.
> 
> I do not see why the "name each rev relative to HEAD" formatting
> option cannot produce HEAD^2~2 etc.
> 
> It would be similar to "git log | git name-rev --stdin" but I do not
> offhand recall if we had a way to tell name-rev to use only HEAD as
> the anchoring point.

My reading was that the OP explicitly wanted to just glance at a single
integer number and use it right away in a subsequent rebase command.

I mean, use one's own short memory instead of copying and pasting.

The way I decided to format the reference in my sketch script — using
HEAD~<n> — is just a byproduct of the fact I was aware both of the
"gitrevisions" manual page and the fact `git name-rev` exists (though I
regretfully was not aware it's able to process a stream of `git log`).

Hence while getting fancy names for revisions would be technically
correct but less error-prone for retyping from memory ;-)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Any way to make git-log to enumerate commits?
  2018-12-06 11:48     ` Konstantin Khomoutov
@ 2018-12-07  0:12       ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2018-12-07  0:12 UTC (permalink / raw)
  To: Konstantin Khomoutov; +Cc: Konstantin Kharlamov, git

Konstantin Khomoutov <kostix@bswap.ru> writes:

>> I do not see why the "name each rev relative to HEAD" formatting
>> option cannot produce HEAD^2~2 etc.
>>  ...
> My reading was that the OP explicitly wanted to just glance at a single
> integer number and use it right away in a subsequent rebase command.
>
> I mean, use one's own short memory instead of copying and pasting.

As everybody pointed out, a single integer number will fundamentally
unworkable with distributed nature of Git that inherently makes the
history with forks and merges.  Besides, there is no way to feed
"git log" with "a single integer number", without which "making
git-log to enumerate" would not be all that useful ("git show
HEAD~4" works but "git show 4" does not).

All of these name-rev based suggestions were about using anchoring
point with memorable name plus a short path to reach from there,
which I think is the closest thing to "a single integer number" and
still is usable for the exact purpose.  "HEAD~48^2" on an
integration branch would be "the tip of the side branch that was
merged some 48 commits ago", for example.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-12-07  0:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 14:22 Any way to make git-log to enumerate commits? Konstantin Kharlamov
2018-12-05 14:54 ` Konstantin Khomoutov
2018-12-05 15:31   ` Elijah Newren
2018-12-05 15:43     ` Andreas Schwab
2018-12-06  0:31   ` Junio C Hamano
2018-12-06 11:48     ` Konstantin Khomoutov
2018-12-07  0:12       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).