git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Git deletes files when rebasing an amended merge-commit.
@ 2015-10-08 12:56 Hans Weltar
  2015-10-08 16:06 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Hans Weltar @ 2015-10-08 12:56 UTC (permalink / raw
  To: git

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Git deletes files when rebasing an amended merge-commit.
  2015-10-08 12:56 Git deletes files when rebasing an amended merge-commit Hans Weltar
@ 2015-10-08 16:06 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2015-10-08 16:06 UTC (permalink / raw
  To: Hans Weltar; +Cc: git

Hans Weltar <hansweltar@gmail.com> writes:

> When you have a fast-forwardable merge commit, you can amend this
> commit to hold additional changes.

The real issue may be that there is a difference between "you can"
and "it is a good idea to", though ;-)

I think the fast-forwardable-ness is a red herring in your example;
rebase by default replays the patches commit by commit to flatten
the history, and evil merges where your result does not match a
mechanical merge result will be lost, and that is true even if you
were dealing with a real merge.

I'd imagine that you would need something like

http://thread.gmane.org/gmane.comp.version-control.git/198125/focus=198516

where it proposes a mode of rebase that picks the change in the
first parent chain.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-08 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-08 12:56 Git deletes files when rebasing an amended merge-commit Hans Weltar
2015-10-08 16:06 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).