{"thread":{"id":"6784","subject":"committing empty diffs","startedAt":"2007-02-12T19:49:36Z","lastAt":"2007-02-12T20:19:42Z","messageCount":5,"participants":["Don Zickus","Shawn O. Pearce","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"34309","messageId":"68948ca0702121149p4d87ae07jd3aa532a0df79156@mail.gmail.com","threadId":"6784","inReplyTo":null,"subject":"committing empty diffs","fromName":"Don Zickus","fromEmail":"dzickus@gmail.com","sentAt":"2007-02-12T19:49:36Z","receivedAt":"2007-02-12T19:49:36Z","isPatch":false,"sender":{"key":"dzickus@gmail.com","avatar":"https://gravatar.com/avatar/fbc96d0d5584c05dec11867b861650fe9f5d7d0ddec2655a1f90542fe07d9769?d=mp&s=160"},"body":"I was toying around with the idea of keeping track of scripts or\nconfig files in my home directory.  Most of the time my commits would\ninclude a change to the file I was tracking.  However, there are a\ncouple of cases where I wanted to commit empty diffs.  For example,\nideas or todos about that particular file that I didn't want to embed\nin the file itself nor write it in yet another file labeled ideas or\ntodos.  I thought it would be easier to just to run a 'git log' on the\nfile and see my whole thought process.\n\nConsidering git-commit doesn't allow this (probably for good reason),\nis it technically safe to do the following sequence of events?\n\ntree=$(git-write-tree)  #basically the same tree HEAD points to\ncommit=$(echo $IDEAS | git-commit-tree $tree -p HEAD)\ngit-update-ref HEAD $commit HEAD\n\nI figured all a commit is doing is taking a snapshot of a particular\ntree at a moment in time.  And taking multiple snapshots at that same\nmoment and stringing them together (pointed to by HEAD) wouldn't be a\nbig deal.\n\nAm I going to wind up shooting myself in the foot later or will this\nwork?  Light testing didn't show any issues.  Thought I would ask the\nexperts.  Thanks.\n\nCheers,\nDon\n"},{"id":"34310","messageId":"20070212200324.GB30440@spearce.org","threadId":"6784","inReplyTo":"68948ca0702121149p4d87ae07jd3aa532a0df79156@mail.gmail.com","subject":"Re: committing empty diffs","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-12T20:03:24Z","receivedAt":"2007-02-12T20:03:24Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Don Zickus <dzickus@gmail.com> wrote:\n> Considering git-commit doesn't allow this (probably for good reason),\n> is it technically safe to do the following sequence of events?\n> \n> tree=$(git-write-tree)  #basically the same tree HEAD points to\n> commit=$(echo $IDEAS | git-commit-tree $tree -p HEAD)\n> git-update-ref HEAD $commit HEAD\n> \n> I figured all a commit is doing is taking a snapshot of a particular\n> tree at a moment in time.  And taking multiple snapshots at that same\n> moment and stringing them together (pointed to by HEAD) wouldn't be a\n> big deal.\n> \n> Am I going to wind up shooting myself in the foot later or will this\n> work?  Light testing didn't show any issues.  Thought I would ask the\n> experts.  Thanks.\n\nNo, it won't break anything.\n\nI do that empty commit myself for a different reason.  I wouldn't\nrecommend that you do that with public history, and since the file\ndidn't change in that commit you cannot do `git log -- foo.c` to\nsee which notes you wrote about foo.c.  But `git log` will still\nshow you the messages.\n\n-- \nShawn.\n"},{"id":"34311","messageId":"Pine.LNX.4.64.0702121202480.8424@woody.linux-foundation.org","threadId":"6784","inReplyTo":"68948ca0702121149p4d87ae07jd3aa532a0df79156@mail.gmail.com","subject":"Re: committing empty diffs","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-02-12T20:10:44Z","receivedAt":"2007-02-12T20:10:44Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 12 Feb 2007, Don Zickus wrote:\n> \n> Considering git-commit doesn't allow this (probably for good reason),\n> is it technically safe to do the following sequence of events?\n\nYes. There's nothing *technically* wrong with an empty commit. The reason \n\"git commit\" doesn't do it is that it's just almost always a mistake.\n\n> tree=$(git-write-tree)  #basically the same tree HEAD points to\n> commit=$(echo $IDEAS | git-commit-tree $tree -p HEAD)\n> git-update-ref HEAD $commit HEAD\n\nIf you know ahead-of-time that the tree is HEAD, there's no reason to do \nthe \"git-write-tree\". You can just use \"HEAD^{tree}\" instead (and in \nfact, I think git-commit-tree will happily just take HEAD directly).\n\nAnd please give a log messages for \"git-update-ref\"\n\nPlease do make sure to do some of the other sanity checks that \"git \ncommit\" does, though. It is a good idea to at least verify that the commit \nmessage isn't empty etc.\n\n\t\tLinus\n"},{"id":"34312","messageId":"20070212201057.GC30440@spearce.org","threadId":"6784","inReplyTo":"20070212200324.GB30440@spearce.org","subject":"Re: committing empty diffs","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-12T20:10:57Z","receivedAt":"2007-02-12T20:10:57Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n> Don Zickus <dzickus@gmail.com> wrote:\n> > Considering git-commit doesn't allow this (probably for good reason),\n> > is it technically safe to do the following sequence of events?\n> > \n> > tree=$(git-write-tree)  #basically the same tree HEAD points to\n> > commit=$(echo $IDEAS | git-commit-tree $tree -p HEAD)\n> > git-update-ref HEAD $commit HEAD\n\nThis can also be written shorter, and safer:\n\n\thead=$(git-rev-parse --verify HEAD^0)\n\tcommit=$(echo $IDEAS | git-commit-tree $head^{tree} -p $head)\n\tgit-update-ref HEAD $commit $head\n\nThe reason you do it like this is it prevents a HEAD which was\nmodified between the time you did git-commit-tree and git-update-ref\nfrom being lost.\n\nAnd the write-tree is completely unnecessary, and might actually\nwrite out a dirty-index, which would make your ideas commit actually\nmodifying files - not what you wanted.\n\n-- \nShawn.\n"},{"id":"34314","messageId":"68948ca0702121219v6056d2dau65c57b47bfc61a00@mail.gmail.com","threadId":"6784","inReplyTo":"20070212200324.GB30440@spearce.org","subject":"Re: committing empty diffs","fromName":"Don Zickus","fromEmail":"dzickus@gmail.com","sentAt":"2007-02-12T20:19:42Z","receivedAt":"2007-02-12T20:19:42Z","isPatch":false,"sender":{"key":"dzickus@gmail.com","avatar":"https://gravatar.com/avatar/fbc96d0d5584c05dec11867b861650fe9f5d7d0ddec2655a1f90542fe07d9769?d=mp&s=160"},"body":"On 2/12/07, Shawn O. Pearce <spearce@spearce.org> wrote:\n> Don Zickus <dzickus@gmail.com> wrote:\n> > Considering git-commit doesn't allow this (probably for good reason),\n> > is it technically safe to do the following sequence of events?\n> >\n> > tree=$(git-write-tree)  #basically the same tree HEAD points to\n> > commit=$(echo $IDEAS | git-commit-tree $tree -p HEAD)\n> > git-update-ref HEAD $commit HEAD\n> >\n> > I figured all a commit is doing is taking a snapshot of a particular\n> > tree at a moment in time.  And taking multiple snapshots at that same\n> > moment and stringing them together (pointed to by HEAD) wouldn't be a\n> > big deal.\n> >\n> > Am I going to wind up shooting myself in the foot later or will this\n> > work?  Light testing didn't show any issues.  Thought I would ask the\n> > experts.  Thanks.\n>\n> No, it won't break anything.\n\nGreat.\n\n>\n> I do that empty commit myself for a different reason.  I wouldn't\n> recommend that you do that with public history, and since the file\n> didn't change in that commit you cannot do `git log -- foo.c` to\n> see which notes you wrote about foo.c.  But `git log` will still\n> show you the messages.\n\nHmm.  Good point.\n\nCheers,\nDon\n"}]}