{"thread":{"id":"14346","subject":"git-rebase eats empty commits","startedAt":"2008-07-08T13:59:16Z","lastAt":"2008-07-16T09:24:38Z","messageCount":5,"participants":["Michael J Gruber","Stephan Beyer"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"82603","messageId":"g4vrrm$g35$1@ger.gmane.org","threadId":"14346","inReplyTo":null,"subject":"git-rebase eats empty commits","fromName":"Michael J Gruber","fromEmail":"michaeljgruber+gmane@fastmail.fm","sentAt":"2008-07-08T13:59:16Z","receivedAt":"2008-07-08T13:59:16Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"\"git commit\" allows empty commits with the \"--allow-empty\" option, i.e. \ncommits which introduce no change at all. This is sometimes useful for \nkeeping a log of untracked work related to tracked content.\n\n\"git rebase\" removes empty commits, for the good reason that rebasing \nmay make certain commits obsolete; but I don't want that in the case \nmentioned above. Is there any way to specify \"--preserve-empty\" or similar?\n\nThe attached script and log show the effect: a series A B C D of commits \nis rebased onto A'; the result is A' C', with the empty commits B and D \ndisappearing.\n\ngrafts and filter-branch helped me solve a particular case of that \neffect, but I think it will show up again, so an option for rebase would \nbe useful.\n\nMichael\n\nP.S.: I also noticed that 'Switched to a new branch \"temp\"' is written \nto stderr, everything else to stdout. Is that as intended?\n\n\nInitialized empty Git repository in /tmp/mjg/t/empty/.git/\nCreated initial commit b3104c1: 1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 a\nCreated commit 7265e0c: empty 1\nCreated commit 9b67221: 2\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 b\nCreated commit 0778af2: empty 2\n0778af2a5003df310cb9dc3c4fff1f8992619610 empty 2\n9b67221a363103ebc78fc052c382637a87ef04e6 2\n7265e0c1a35c95bd6fcf739a9f815b300ba9d9cc empty 1\nb3104c148e1dd6ce8fd23cddb71734e45e7d9132 1\nSwitched to a new branch \"temp\"\nCreated commit d9ad4bc: rewritten 1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 a\nFirst, rewinding head to replay your work on top of it...\nApplying 2\nd81ec616edd3ed600a60dbd63d4d0f4a7263387f 2\nd9ad4bcd2fb5e78f2f430733f2dc36453a653221 rewritten 1\n"},{"id":"83107","messageId":"20080712221207.GB22323@leksak.fem-net","threadId":"14346","inReplyTo":"g4vrrm$g35$1@ger.gmane.org","subject":"Re: git-rebase eats empty commits","fromName":"Stephan Beyer","fromEmail":"s-beyer@gmx.net","sentAt":"2008-07-12T22:12:07Z","receivedAt":"2008-07-12T22:12:07Z","isPatch":false,"sender":{"key":"s-beyer@gmx.net","avatar":"https://avatars.githubusercontent.com/u/143889?v=4"},"body":"Hi,\n\nMichael J Gruber wrote:\n> \"git commit\" allows empty commits with the \"--allow-empty\" option, i.e.  \n> commits which introduce no change at all. This is sometimes useful for  \n> keeping a log of untracked work related to tracked content.\n>\n> \"git rebase\" removes empty commits, for the good reason that rebasing  \n> may make certain commits obsolete; but I don't want that in the case  \n> mentioned above. Is there any way to specify \"--preserve-empty\" or \n> similar?\n\nFirst I can speak for git-sequencer: there is no such thing as a\n\"preserve empty\" option, but currently, when you are picking a commit\nthat has already been applied so that no changes occur, it will pause.\n(It will not pause if it is a fast-forward.)\nYet, I was unsure if this is a \"correct\" behavior, but it seemed to be\nuseful, because you can inspect the situation.\n\nIn my mind, the same should happen with an empty commit, so I tested it:\n 1. It pauses.\n 2. In that pause I only need to run \"git commit --allow-empty\" and I have\n    the picked empty patch with that commit message.\n\nSo if this behavior is kept, there is no such need for such an option.\n\nNow I'm checking it with the old rebase-i (I'm always referring to\ngit-rebase--interactive as rebase-i) and exactly the same behavior\noccurs.\n\nBut rebase is not rebase-i.\nSo I've also checked both, pure rebase and rebase-m: then the empty commit\nis lost.\n\nTo sum up, use rebase -i and when it's pausing, do \"git commit --allow-empty\"\nand then \"git rebase --continue\" and you have what you want.\n\nRegards,\n  Stephan\n\n-- \nStephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F\n"},{"id":"83269","messageId":"g5fpnm$3jb$1@ger.gmane.org","threadId":"14346","inReplyTo":"20080712221207.GB22323@leksak.fem-net","subject":"Re: git-rebase eats empty commits","fromName":"Michael J Gruber","fromEmail":"michaeljgruber+gmane@fastmail.fm","sentAt":"2008-07-14T15:01:08Z","receivedAt":"2008-07-14T15:01:08Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Stephan Beyer venit, vidit, dixit 13.07.2008 00:12:\n> Hi,\n> \n> Michael J Gruber wrote:\n>> \"git commit\" allows empty commits with the \"--allow-empty\" option, i.e.  \n>> commits which introduce no change at all. This is sometimes useful for  \n>> keeping a log of untracked work related to tracked content.\n>>\n>> \"git rebase\" removes empty commits, for the good reason that rebasing  \n>> may make certain commits obsolete; but I don't want that in the case  \n>> mentioned above. Is there any way to specify \"--preserve-empty\" or \n>> similar?\n> \n> First I can speak for git-sequencer: there is no such thing as a\n> \"preserve empty\" option, but currently, when you are picking a commit\n> that has already been applied so that no changes occur, it will pause.\n> (It will not pause if it is a fast-forward.)\n> Yet, I was unsure if this is a \"correct\" behavior, but it seemed to be\n> useful, because you can inspect the situation.\n> \n> In my mind, the same should happen with an empty commit, so I tested it:\n>  1. It pauses.\n>  2. In that pause I only need to run \"git commit --allow-empty\" and I have\n>     the picked empty patch with that commit message.\n> \n> So if this behavior is kept, there is no such need for such an option.\n> \n> Now I'm checking it with the old rebase-i (I'm always referring to\n> git-rebase--interactive as rebase-i) and exactly the same behavior\n> occurs.\n> \n> But rebase is not rebase-i.\n> So I've also checked both, pure rebase and rebase-m: then the empty commit\n> is lost.\n> \n> To sum up, use rebase -i and when it's pausing, do \"git commit --allow-empty\"\n> and then \"git rebase --continue\" and you have what you want.\n\nI assume this is with git from master? With git 1.5.6.2 rebase -i \ndoesn't stop there, not even when I change \"pick\" to \"edit\"!\n\nSo, I guess for now I'll use my hacked git-rebase (\"-m\", I didn't hack \ngit-format-patch), maybe 1.6.0 will behave as described above. Anyway \nthanks for the hint about distinguishing between rebase and rebase -i.\n\nMichael\n"},{"id":"83428","messageId":"20080715201902.GC6244@leksak.fem-net","threadId":"14346","inReplyTo":"g5fpnm$3jb$1@ger.gmane.org","subject":"Re: git-rebase eats empty commits","fromName":"Stephan Beyer","fromEmail":"s-beyer@gmx.net","sentAt":"2008-07-15T20:19:02Z","receivedAt":"2008-07-15T20:19:02Z","isPatch":false,"sender":{"key":"s-beyer@gmx.net","avatar":"https://avatars.githubusercontent.com/u/143889?v=4"},"body":"Hi,\n\nMichael J Gruber wrote:\n> Stephan Beyer venit, vidit, dixit 13.07.2008 00:12:\n>> To sum up, use rebase -i and when it's pausing, do \"git commit --allow-empty\"\n>> and then \"git rebase --continue\" and you have what you want.\n>\n> I assume this is with git from master? With git 1.5.6.2 rebase -i  \n> doesn't stop there, not even when I change \"pick\" to \"edit\"!\n\nHmm, in fact this is with my git from Debian, from master and my\nsequencer-based one:\n\n\t$ /usr/bin/git --version\n\tgit version 1.5.6\n\t$ ./git --version\n\tgit version 1.5.6.3.350.g6c11a\n\t$ git --version\n\tgit version 1.5.6.3.506.g902dd\n\nAnd, btw, the reason of this behavior is no special case in rebase-i,\nit's just that git-cherry-pick fails (exit status != 0), if you pick an\nempty commit (and then rebase-i will pause because of conflict). And\n*this* is because builtin-revert.c runs git-commit without --allow-empty.\nThis has never changed, so I cannot believe that the behavior changed in\nany version of git. Or I am missing a point.\n\n\t$ git cherry-pick empty\t\t# empty is an empty commit tagged as \"empty\"\n\tAlready uptodate!\n\tFinished one cherry-pick.\n\t# Not currently on any branch.\n\t# Untracked files:\n\t[...]\n\tnothing added to commit but untracked files present (use \"git add\" to track)\n\t$ echo $?\n\t1\n\t$ EDITOR=touch git commit --allow-empty\n\tCreated commit 145f1d0: empty\n\nThe same happens when doing rebase -i instead of cherry-pick.\n\nRegards,\n  Stephan\n\n-- \nStephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F\n"},{"id":"83488","messageId":"487DBE56.9020201@fastmail.fm","threadId":"14346","inReplyTo":"20080715201902.GC6244@leksak.fem-net","subject":"Re: git-rebase eats empty commits","fromName":"Michael J Gruber","fromEmail":"michaeljgruber+gmane@fastmail.fm","sentAt":"2008-07-16T09:24:38Z","receivedAt":"2008-07-16T09:24:38Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Stephan Beyer venit, vidit, dixit 15.07.2008 22:19:\n> Hi,\n...\n> any version of git. Or I am missing a point.\n> \n> \t$ git cherry-pick empty\t\t# empty is an empty commit tagged as \"empty\"\n> \tAlready uptodate!\n> \tFinished one cherry-pick.\n> \t# Not currently on any branch.\n> \t# Untracked files:\n> \t[...]\n> \tnothing added to commit but untracked files present (use \"git add\" to track)\n\nHow would an empty commit produce untracked files? You seem to be \ntesting something different.\n\nI reattach the test case from my original post, as well as the log of \nruns with git 1.5.6.3: once with rebase and once with rebase -i.\n\nUuuh, doh: I interpreted\n\nFinished one cherry-pick.\n# Not currently on any branch.\nnothing to commit (working directory clean)\nCould not apply e1f497c... empty 1\n8d0c67a675bc65d375e8a9d019500bb2a16fb1e9 rewritten 1\n\nas the end of the (interactive) rebase operation! Nothing indicated it \nwas interrupted: no message and no git status output. It all looked like \na failed rebase.\n\nNow, thanks to your persistence, I tried going ahead with commit --amend \nand rebase --continue, and all went fine (stopped again for empty 2, \ngiving no clue; amend & cont).\n\nSo, you're right: cherry-pick stops at empty commits, so that rebase -i \nis the way to go. rebase (non-i) uses format-patch resp. merge (-m), \nwhich eat empty commits.\n\nI recall some discussion about informative rb-i messages, may upcoming \ngit would have saved me and will save others from this misinterpretation.\n\nThanks!\nMichael\n\n\nInitialized empty Git repository in /tmp/mjg/t/empty/.git/\nCreated initial commit 6b9e2af: 1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 a\nCreated commit 8387962: empty 1\nCreated commit 6c4c3fe: 2\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 b\nCreated commit 3521900: empty 2\n3521900fb7b032aa9e1f5a50a82f71785aa5c208 empty 2\n6c4c3fe8b7619e1107256d0b47d0f419c05ceb69 2\n8387962b740bb47662dd866eb57b4fe5ad21b355 empty 1\n6b9e2afad8bed27378f0c9d23e77631be8447d37 1\nSwitched to a new branch \"temp\"\nCreated commit 1cced89: rewritten 1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 a\nFirst, rewinding head to replay your work on top of it...\nApplying 2\na4116113335fc6be47fb9f8481547ea0923ac09d 2\n1cced892a90024f4230a9f7aec1989ffe0b6c16f rewritten 1\n\n\nInitialized empty Git repository in /tmp/mjg/t/empty/.git/\nCreated initial commit 2796c9d: 1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 a\nCreated commit e1f497c: empty 1\nCreated commit b3867ae: 2\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 b\nCreated commit 2edad43: empty 2\n2edad436286f39e407b83bbb448b3aa62b91aeb9 empty 2\nb3867ae2a345ab30bfd68a1c7e0e19999a1eb9eb 2\ne1f497c4ee7a040162faa7dcc2b6d8e41d5fd920 empty 1\n2796c9d9f8fced86134e5b36462916c938c6f819 1\nSwitched to a new branch \"temp\"\nCreated commit 8d0c67a: rewritten 1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 a\nRebasing (1/3)\rAlready uptodate!\nFinished one cherry-pick.\n# Not currently on any branch.\nnothing to commit (working directory clean)\nCould not apply e1f497c... empty 1\n8d0c67a675bc65d375e8a9d019500bb2a16fb1e9 rewritten 1\n"}]}