git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-rebase eats empty commits

From
Michael J Gruber <michaeljgruber+gmane@fastmail.fm>
Date
Jul 8, 2008, 13:59 UTC
Message-ID
<g4vrrm$g35$1@ger.gmane.org>

"git commit" allows empty commits with the "--allow-empty" option, i.e. commits which introduce no change at all. This is sometimes useful for keeping a log of untracked work related to tracked content.

"git rebase" removes empty commits, for the good reason that rebasing may make certain commits obsolete; but I don't want that in the case mentioned above. Is there any way to specify "--preserve-empty" or similar?

The attached script and log show the effect: a series A B C D of commits is rebased onto A'; the result is A' C', with the empty commits B and D disappearing.

grafts and filter-branch helped me solve a particular case of that effect, but I think it will show up again, so an option for rebase would be useful.

Michael

P.S.: I also noticed that 'Switched to a new branch "temp"' is written to stderr, everything else to stdout. Is that as intended?

Initialized empty Git repository in /tmp/mjg/t/empty/.git/
Created initial commit b3104c1: 1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a
Created commit 7265e0c: empty 1
Created commit 9b67221: 2
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 b
Created commit 0778af2: empty 2
0778af2a5003df310cb9dc3c4fff1f8992619610 empty 2
9b67221a363103ebc78fc052c382637a87ef04e6 2
7265e0c1a35c95bd6fcf739a9f815b300ba9d9cc empty 1
b3104c148e1dd6ce8fd23cddb71734e45e7d9132 1
Switched to a new branch "temp"
Created commit d9ad4bc: rewritten 1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a
First, rewinding head to replay your work on top of it...
Applying 2
d81ec616edd3ed600a60dbd63d4d0f4a7263387f 2
d9ad4bcd2fb5e78f2f430733f2dc36453a653221 rewritten 1
Next: Stephan Beyer
Message 1 of 5 in “git-rebase eats empty commits”
  1. Michael J GruberJul 8, 2008
  2. Stephan BeyerJul 12, 2008
  3. Michael J GruberJul 14, 2008
  4. Stephan BeyerJul 15, 2008
  5. Michael J GruberJul 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.