{"thread":{"id":"30222","subject":"'git log' numbering commits?","startedAt":"2012-04-12T07:54:12Z","lastAt":"2012-04-12T18:14:15Z","messageCount":4,"participants":["Daniel Wagner","Jeff King","Philippe Vaucher"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"189088","messageId":"4F868A24.9090004@monom.org","threadId":"30222","inReplyTo":null,"subject":"'git log' numbering commits?","fromName":"Daniel Wagner","fromEmail":"wagi@monom.org","sentAt":"2012-04-12T07:54:12Z","receivedAt":"2012-04-12T07:54:12Z","isPatch":false,"sender":{"key":"wagi@monom.org","avatar":null},"body":"Hi,\n\nI have a stupid question I could not answer myself when reading the\nexcellent documentation.\n\nMy workflow involves a lot of \"git rebase -i\". For figuring out which\ncommit id to use I do first a 'git log --oneline'. Then I do copy past\nthe id to the 'git rebase -i'. The reason why I don't use relative\nid such as HEAD~4, because I keep miscounting the commits.\n\nSo my question is there a magic option to have git log to enumerate the\ncommits, e.g.\n\n1: 2fcd2b3 network: Remove unused function\n2: b376b2a session: Fix introspection for Change()\n3: 15c9cd0 wifi: Refactor desctruction of network object\n4: a9c699f network: Remove device pointer in network_remove()\n[...]\n\ncheers,\ndaniel\n"},{"id":"189092","messageId":"20120412084122.GG31122@sigill.intra.peff.net","threadId":"30222","inReplyTo":"4F868A24.9090004@monom.org","subject":"Re: 'git log' numbering commits?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-04-12T08:41:23Z","receivedAt":"2012-04-12T08:41:23Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 12, 2012 at 09:54:12AM +0200, Daniel Wagner wrote:\n\n> My workflow involves a lot of \"git rebase -i\". For figuring out which\n> commit id to use I do first a 'git log --oneline'. Then I do copy past\n> the id to the 'git rebase -i'. The reason why I don't use relative\n> id such as HEAD~4, because I keep miscounting the commits.\n> \n> So my question is there a magic option to have git log to enumerate the\n> commits, e.g.\n> \n> 1: 2fcd2b3 network: Remove unused function\n> 2: b376b2a session: Fix introspection for Change()\n> 3: 15c9cd0 wifi: Refactor desctruction of network object\n> 4: a9c699f network: Remove device pointer in network_remove()\n\nNo, there is no such feature. You can do this:\n\n  git log --oneline | nl \"-s: \"\n\nbut that will just give you the count of commits shown. If the history\nis not a single line of development, then those numbers will become\nmeaningless quickly. Also note that there is an off-by-one in this\nscheme; HEAD~2 will be numbered as \"3\".\n\nIf you wanted to simply decorate each commit with a more readable name,\nyou could do this:\n\n  git log --format='%H: %s' |\n  git name-rev --stdin --name-only\n\nthough for simplicity, you may find that you prefer to name only based on\nthe current tip. You can do that like this:\n\n  git log --format='%H: %s' |\n  git name-rev --stdin --name-only \\\n    --refs `git symbolic-ref HEAD`\n\nwhich yields output like:\n\n  your-topic: network: Remove unused function\n  your-topic~1: session: Fix introspection for Change()\n  your-topic~2: wifi: Refactor desctruction of network object\n  your-topic~3: network: Remove device pointer in network_remove()\n\nHowever, if you really just want this to make \"rebase -i\" easier, have\nyou considered setting the upstream branch config for your branches?\nWhen I create a topic branch, I do:\n\n  git checkout -b topic origin/master\n\nAnd then \"git rebase -i @{upstream}\" rebases everything up to my\nupstream branch (origin/master). That may be slightly more than I want,\nbut it lets me see the whole series in the \"rebase -i\" sequencer. Recent\nversions of git even default to \"@{upstream}\", so you can just say \"git rebase\n-i\".\n\nHow do you usually create your branches? What version of git are you\nusing (the \"@{upstream}\" default is in v1.7.6 and later)?\n\n-Peff\n"},{"id":"189096","messageId":"4F869D4C.8090108@monom.org","threadId":"30222","inReplyTo":"20120412084122.GG31122@sigill.intra.peff.net","subject":"Re: 'git log' numbering commits?","fromName":"Daniel Wagner","fromEmail":"wagi@monom.org","sentAt":"2012-04-12T09:15:56Z","receivedAt":"2012-04-12T09:15:56Z","isPatch":false,"sender":{"key":"wagi@monom.org","avatar":null},"body":"Hi Jeff,\n\nOn 12.04.2012 10:41, Jeff King wrote:\n> On Thu, Apr 12, 2012 at 09:54:12AM +0200, Daniel Wagner wrote:\n> \n>> My workflow involves a lot of \"git rebase -i\". For figuring out which\n>> commit id to use I do first a 'git log --oneline'. Then I do copy past\n>> the id to the 'git rebase -i'. The reason why I don't use relative\n>> id such as HEAD~4, because I keep miscounting the commits.\n>>\n>> So my question is there a magic option to have git log to enumerate the\n>> commits, e.g.\n>>\n>> 1: 2fcd2b3 network: Remove unused function\n>> 2: b376b2a session: Fix introspection for Change()\n>> 3: 15c9cd0 wifi: Refactor desctruction of network object\n>> 4: a9c699f network: Remove device pointer in network_remove()\n> \n> No, there is no such feature. You can do this:\n> \n>   git log --oneline | nl \"-s: \"\n\nObviously, I tend to forget the power of the pipes :)\n\n> but that will just give you the count of commits shown. If the history\n> is not a single line of development, then those numbers will become\n> meaningless quickly. Also note that there is an off-by-one in this\n> scheme; HEAD~2 will be numbered as \"3\".\n> \n> If you wanted to simply decorate each commit with a more readable name,\n> you could do this:\n> \n>   git log --format='%H: %s' |\n>   git name-rev --stdin --name-only\n> \n> though for simplicity, you may find that you prefer to name only based on\n> the current tip. You can do that like this:\n> \n>   git log --format='%H: %s' |\n>   git name-rev --stdin --name-only \\\n>     --refs `git symbolic-ref HEAD`\n> \n> which yields output like:\n> \n>   your-topic: network: Remove unused function\n>   your-topic~1: session: Fix introspection for Change()\n>   your-topic~2: wifi: Refactor desctruction of network object\n>   your-topic~3: network: Remove device pointer in network_remove()\n\nDidn't know about name-ref. Very cool :)\n\n> However, if you really just want this to make \"rebase -i\" easier, have\n> you considered setting the upstream branch config for your branches?\n> When I create a topic branch, I do:\n\nMaybe I should have mentioned that on those project I am mostly working,\nwe don't have branches (ConnMan, BlueZ, oFono). So we have a very simple\nhistory.\n\n>   git checkout -b topic origin/master\n> \n> And then \"git rebase -i @{upstream}\" rebases everything up to my\n> upstream branch (origin/master). That may be slightly more than I want,\n> but it lets me see the whole series in the \"rebase -i\" sequencer. Recent\n> versions of git even default to \"@{upstream}\", so you can just say \"git rebase\n> -i\".\n\nThe main reason I avoided branches is that I have several topics at the\nsame time and having a single branch and maintaining them by hand was so\nfar easier.\n\n> How do you usually create your branches? What version of git are you\n> using (the \"@{upstream}\" default is in v1.7.6 and later)?\n\nNormally I only have for big changes branches but for a few independent\nfixed I just use the master branch and fix the patches. But I see, I\nshould over think my workflow here :)\n\nI am using git trunk :) I'll try the @{upstream} trick.\n\nThanks a lot for this elaborate answer.\n\ncheers,\ndaniel\n"},{"id":"189125","messageId":"CAGK7Mr4kPp+vTM2OrQ3MqcnGy3KsXj9yr1BThm57jrUqk-46Yg@mail.gmail.com","threadId":"30222","inReplyTo":"4F869D4C.8090108@monom.org","subject":"Re: 'git log' numbering commits?","fromName":"Philippe Vaucher","fromEmail":"philippe.vaucher@gmail.com","sentAt":"2012-04-12T18:14:15Z","receivedAt":"2012-04-12T18:14:15Z","isPatch":false,"sender":{"key":"philippe.vaucher@gmail.com","avatar":null},"body":"> I am using git trunk :) I'll try the @{upstream} trick.\n\nNot sure if it helps, but I use something that is somewhat easier to\nremember for me (specifying the upstream manualy):\n\ngit rebase -i origin/master\n\nPhilippe\n"}]}