{"thread":{"id":"7320","subject":"how to do these 2 one-liners ?","startedAt":"2007-03-19T22:25:41Z","lastAt":"2007-03-19T23:09:51Z","messageCount":4,"participants":["Christian MICHON","Junio C Hamano","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"37553","messageId":"46d6db660703191525w613b02e1nae0f30efaca3b269@mail.gmail.com","threadId":"7320","inReplyTo":null,"subject":"how to do these 2 one-liners ?","fromName":"Christian MICHON","fromEmail":"christian.michon@gmail.com","sentAt":"2007-03-19T22:25:41Z","receivedAt":"2007-03-19T22:25:41Z","isPatch":false,"sender":{"key":"christian.michon@gmail.com","avatar":"https://gravatar.com/avatar/8a7c327b21187fbcab5c27640a49450eec72e0355dc292501197f27a5a744ec4?d=mp&s=160"},"body":"Hi list,\n\nin order to code a gvim plugin for git (I started something), I now miss\n2 one-liners, and I hope experts around this list will find it easy\nto answer (for the sake of this plugin)\n\n================================================\n1) how do I check the status of a single file ? ( the file is already\nadded in the index)\n\nI usually use git-status here, but for single files that need update,\nthere should be a faster way.\n\n================================================\n2) how do I find in historical reverse order all the commits a\ncertain file belongs to since the origin ?\n\nI usually do: git-log <file> | grep ^commit\nI would like to avoid piping here...\n\nI may need more than these 2 one-liners, if they're doable.\nI'll post something soon :)\nThanks in advance!\n\n-- \nChristian\n"},{"id":"37556","messageId":"7vwt1cetuc.fsf@assigned-by-dhcp.cox.net","threadId":"7320","inReplyTo":"46d6db660703191525w613b02e1nae0f30efaca3b269@mail.gmail.com","subject":"Re: how to do these 2 one-liners ?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-19T22:44:59Z","receivedAt":"2007-03-19T22:44:59Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Christian MICHON\" <christian.michon@gmail.com> writes:\n\n> ================================================\n> 1) how do I check the status of a single file ? ( the file is already\n> added in the index)\n>\n> I usually use git-status here, but for single files that need update,\n> there should be a faster way.\n\n\"git-diff-files $PATH\" shows if it is different relative to the\nindex, \"git-diff-index HEAD $PATH\" shows if it is different from\nthe HEAD, and \"git-diff-index --cached $PATH\" shows if it is\ndifferent between index and HEAD.  git-status uses the first one\nand the third one AFAIR.  You say \"that need update\", so\nprobably you are interested in seeing the first one only without\nthe third one.\n\nIf you have Git 1.5.1, then:\n\n\tif git diff-files --quiet $PATH\n        then\n        \techo Up to date\n\telse\n        \techo Need update\n\tfi                \n\nAnother more portable way is:\n\n\tif test -z \"$(git diff-files --raw $PATH)\"\n        then\n        \techo Up to date\n\telse\n        \techo Need update\n\tfi                \n\n> ================================================\n> 2) how do I find in historical reverse order all the commits a\n> certain file belongs to since the origin ?\n>\n> I usually do: git-log <file> | grep ^commit\n> I would like to avoid piping here...\n\ngit-rev-list -m HEAD -- \"$PATH\"\n"},{"id":"37557","messageId":"46d6db660703191559s56f13734w45c6ce65fe604f4a@mail.gmail.com","threadId":"7320","inReplyTo":"7vwt1cetuc.fsf@assigned-by-dhcp.cox.net","subject":"Re: how to do these 2 one-liners ?","fromName":"Christian MICHON","fromEmail":"christian.michon@gmail.com","sentAt":"2007-03-19T22:59:52Z","receivedAt":"2007-03-19T22:59:52Z","isPatch":false,"sender":{"key":"christian.michon@gmail.com","avatar":"https://gravatar.com/avatar/8a7c327b21187fbcab5c27640a49450eec72e0355dc292501197f27a5a744ec4?d=mp&s=160"},"body":"On 3/19/07, Junio C Hamano <junkio@cox.net> send 2 nice\none-liners...\n\nThanks Junio :)\n\nI'll use these 2 tomorrow. I wasn't that far in my last experiments\nfor the 2nd one...\n\n-- \nChristian\n"},{"id":"37559","messageId":"Pine.LNX.4.64.0703191549100.6730@woody.linux-foundation.org","threadId":"7320","inReplyTo":"46d6db660703191525w613b02e1nae0f30efaca3b269@mail.gmail.com","subject":"Re: how to do these 2 one-liners ?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-03-19T23:09:51Z","receivedAt":"2007-03-19T23:09:51Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 19 Mar 2007, Christian MICHON wrote:\n> \n> in order to code a gvim plugin for git (I started something), I now miss\n> 2 one-liners, and I hope experts around this list will find it easy\n> to answer (for the sake of this plugin)\n> \n> ================================================\n> 1) how do I check the status of a single file ? ( the file is already\n> added in the index)\n\nIt really depends on what you want to do.\n\nIf you want to know *what* the index contains right there and then, do for \nexample:\n\n\tgit ls-files --stage -- \"$filename\"\n\nand it will tell you the index contents (it might be several lines: if the \n\"filename\" entry is a directory it will list *all* files under that \ndirectory, but even if it's a single file it could give you all the \nunmerged stages for that file).\n\nOn the other hand, often you want to know what the status of a file is not \nin \"absolute\" terms, but relative to the index or to the last commit. If \nso, you can use something like\n\n\tgit diff-files --name-status -- \"$filename\"\n\nwhich just compares the index with the current working tree. And if you \nwant to check against the last commit (ie HEAD), use\n\n\tgit diff-index --name-status HEAD -- \"$filename\"\n\nwhich can also be used with \"--cached\" to see the difference between the \nHEAD and the index. That's how \"git status\" used to do it when it was a \nshell script (now it's done with a built-in).\n\nIn fact, you could look at the old git-commit.sh script before it was \nturned into a built-in with\n\n\tgit show v1.4.0:git-commit.sh\n\nand look at the \"run_status\" shell function.\n\n> I usually use git-status here, but for single files that need update,\n> there should be a faster way.\n\nIndeed. HOWEVER! Note that when you ask for the status of a single file, \nthat obviously means that there is no \"rename detection\" going on, so if \nyou want to see the \"renamed from Xyz\", you need to do the global analysis \nthat \"git-status\" does, and then fetch the filename info from there.\n\n(Alternatively, you can choose to always do the single-file case first, \nand then only *if* it's a newly added file you could ask \"was it renamed \nfrom anything else\").\n\n> 2) how do I find in historical reverse order all the commits a\n> certain file belongs to since the origin ?\n\nThat's quite an expensive operation:\n\n\tgit rev-list --reverse HEAD -- \"$filename\"\n\nOr did you by \"historical\" mean \"newest first\"? If so, just do\n\n\tgit rev-list HEAD -- \"$filename\"\n\n(that's the order that git considers \"natural\").\n\n> I usually do: git-log <file> | grep ^commit\n> I would like to avoid piping here...\n\nWell, \"git log\" is really just rev-list with fancy options to make it show \nmore than just the commit name.\n\nOf course, you *could* do\n\n\tgit log --pretty=oneline -- \"$filename\"\n\nwhich gets you pretty close. But if you literally just want the commit \nSHA1, \"git rev-list\" is what you're really asking for.\n\n\t\t\tLinus\n"}]}