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

Git deletes files when rebasing an amended merge-commit.

From
HWHans Weltar <hansweltar@gmail.com>
Date
Oct 8, 2015, 12:56 UTC
Message-ID
<CAJqY2NUHg-7ghiNA7m+Q36LPhgG6tC6QDg2BP6f52fvDv6uAWQ@mail.gmail.com>

When you have a fast-forwardable merge commit, you can amend this commit to hold additional changes. When you now do a rebase, git will believe this merge-commit is fast-forwardable, and will delete all amended changes. I believe when you amend a merge-commit it should become non-fastforwardable.

As rebase often needs to be applied (eg rebase -i; pull --rebase) this is a rather insidious way to loose files without warning.

Here's a small testcase that creates a ff merge commit holding files f1, f2 and f3. When you execute the last rebase command, the f3 file will disappear from the filesystem.

git init touch f1; git add f1; git commit -m "add f1" git checkout -b mybranch touch f2; git add f2; git commit -m "add f2" git checkout master git merge mybranch --no-ff -m "Merge mybranch" touch f3; git add f3 git commit --amend -m "Add f2 and f3" # Amend merge git rebase HEAD^ # f3 will sneakily be deleted, breaking the build and giving you CI duty :)

kind regards Hans

Next: Junio C Hamano
Message 1 of 2 in “Git deletes files when rebasing an amended merge-commit.”
  1. Hans WeltarOct 8, 2015
  2. Junio C HamanoOct 8, 2015

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.