{"thread":{"id":"40518","subject":"Git deletes files when rebasing an amended merge-commit.","startedAt":"2015-10-08T12:56:44Z","lastAt":"2015-10-08T16:06:07Z","messageCount":2,"participants":["Hans Weltar","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"271317","messageId":"CAJqY2NUHg-7ghiNA7m+Q36LPhgG6tC6QDg2BP6f52fvDv6uAWQ@mail.gmail.com","threadId":"40518","inReplyTo":null,"subject":"Git deletes files when rebasing an amended merge-commit.","fromName":"Hans Weltar","fromEmail":"hansweltar@gmail.com","sentAt":"2015-10-08T12:56:44Z","receivedAt":"2015-10-08T12:56:44Z","isPatch":false,"sender":{"key":"hansweltar@gmail.com","avatar":null},"body":"When you have a fast-forwardable merge commit, you can amend this\ncommit to hold additional changes.\nWhen you now do a rebase, git will believe this merge-commit is\nfast-forwardable, and will delete all amended changes.\nI believe when you amend a merge-commit it should become non-fastforwardable.\n\nAs rebase often needs to be applied (eg rebase -i; pull --rebase) this\nis a rather insidious way to loose files without warning.\n\nHere's a small testcase that creates a ff merge commit holding files\nf1, f2 and f3. When you execute the last rebase command, the f3 file\nwill disappear from the filesystem.\n\ngit init\ntouch f1; git add f1; git commit -m \"add f1\"\ngit checkout -b mybranch\ntouch f2; git add f2; git commit -m \"add f2\"\ngit checkout master\ngit merge mybranch --no-ff -m \"Merge mybranch\"\ntouch f3; git add f3\ngit commit --amend -m \"Add f2 and f3\" # Amend merge\ngit rebase HEAD^ # f3 will sneakily be deleted, breaking the build and\ngiving you CI duty :)\n\nkind regards\nHans\n"},{"id":"271319","messageId":"xmqqegh5s5u8.fsf@gitster.mtv.corp.google.com","threadId":"40518","inReplyTo":"CAJqY2NUHg-7ghiNA7m+Q36LPhgG6tC6QDg2BP6f52fvDv6uAWQ@mail.gmail.com","subject":"Re: Git deletes files when rebasing an amended merge-commit.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-08T16:06:07Z","receivedAt":"2015-10-08T16:06:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hans Weltar <hansweltar@gmail.com> writes:\n\n> When you have a fast-forwardable merge commit, you can amend this\n> commit to hold additional changes.\n\nThe real issue may be that there is a difference between \"you can\"\nand \"it is a good idea to\", though ;-)\n\nI think the fast-forwardable-ness is a red herring in your example;\nrebase by default replays the patches commit by commit to flatten\nthe history, and evil merges where your result does not match a\nmechanical merge result will be lost, and that is true even if you\nwere dealing with a real merge.\n\nI'd imagine that you would need something like\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/198125/focus=198516\n\nwhere it proposes a mode of rebase that picks the change in the\nfirst parent chain.\n\nThanks.\n"}]}