{"thread":{"id":"54887","subject":"RE: How can I search git log with ceratin keyword but without the other keyword?","startedAt":"2020-12-27T23:46:07Z","lastAt":"2020-12-27T23:46:07Z","messageCount":1,"participants":["Dan Moseley"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"413038","messageId":"BYAPR21MB1158BDAEA538A78A528B6010E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com","threadId":"54887","inReplyTo":"BYAPR21MB11587632058438090FE265B8E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com","subject":"RE: How can I search git log with ceratin keyword but without the other keyword?","fromName":"Dan Moseley","fromEmail":"dan.moseley@microsoft.com","sentAt":"2020-12-27T23:45:07Z","receivedAt":"2020-12-27T23:46:07Z","isPatch":false,"sender":{"key":"dan.moseley@microsoft.com","avatar":null},"body":"Apologies, that was HTML. \n\nFrom: Dan Moseley \nSent: Sunday, December 27, 2020 3:42 PM\nTo: peff@peff.net\nCc: carenas@gmail.com; git@vger.kernel.org; sunshilong369@gmail.com\nSubject: Re: How can I search git log with ceratin keyword but without the other keyword?\n\n\n>> I wonder why this command doesn't work well.\n>> I intend to find the comment with the keyword \"12\" but without \"comments\"\n>> whereas the output is something like this:\n>> \n>> git log --perl-regexp --all-match --grep=12 --grep '\\b(?!comments\\b)\\w+'\n>> commit f5b6c3e33bd2559d6976b1d589071a5928992601\n>> Author: sunshilong <mailto:sunshilong369@gmail.com>\n>> Date:   2020-04-12 23:00:29 +0800\n>> \n>>     comments 2020.04.12 ng\n>\n>I think this is the thing I was mentioning earlier. That negative\n>lookahead means the second one wouldn't match \"comments\", but it would\n>still match \"2020.04.12\" or \"ng\". So it won't do what you want.\n>\n>I can't think of a way to do what you want just a regex, but maybe\n>somebody more clever than me can.\n\ngit log --perl-regexp --grep='^(?!.*comments).*12.*$'\n\nThe first part fails to match if the line contains 'comments' but it does not consume anything, so the second part '.*12.*' begins at the start of the line and matches '12' anywhere in the line.\n\nOf course you can extend the positive and negative parts, e.g.,\n\ngit log --perl-regexp --grep='^(?!.*(comments|abc)).*(12|def).*$'\n\nmeans \"lines that don't contain `comments` and don't contain `abc` but do contain `12` or `def`\n\n- Dan\n\n"}]}