{"thread":{"id":"47806","subject":"Question about rebasing - unexpected result, can't figure out why","startedAt":"2018-02-10T20:55:15Z","lastAt":"2018-02-13T00:36:39Z","messageCount":2,"participants":["Jonas Thiem","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"338995","messageId":"44e87a5a-b2be-f3f5-ac98-6831e056152d@thiem.email","threadId":"47806","inReplyTo":null,"subject":"Question about rebasing - unexpected result, can't figure out why","fromName":"Jonas Thiem","fromEmail":"jonas@thiem.email","sentAt":"2018-02-10T20:47:57Z","receivedAt":"2018-02-10T20:55:15Z","isPatch":false,"sender":{"key":"jonas@thiem.email","avatar":null},"body":"Hi *,\n\nI did some experimenting to understand rebasing better. I'm trying to\nfollow ProGit 2nd edition. I used the repository example from here:\n\nhttps://git-scm.com/book/en/v2/Git-Branching-Rebasing#rbdiag_e\n\nI did a short test setup and did a few rebases, expecting a certain\nresult from my limited understanding of rebases. Sadly, I got something\nelse, and I can't figure out why.\n\n== Setup ==\n\nThe repository is present in the attached archive in folder:\n./rebase-experiment/repo-before-rebases/\n\nThe graph is as in the linked book example above.\nI set up the commits (named same as in the book) in the following way:\n\nC1: adds file C1.txt\nC2: adds file C2.txt\nC3: adds file C3.txt\nC4: adds file C4.txt\nC5: adds file C5.txt\nC6: adds file C6.txt\nC8: deletes file C3.txt (following C3 which added it)\nC9: adds file C9.txt\nC10: adds file C10.txt\n\nThen I did the following rebases:\n\ngit checkout client && git rebase master\ngit checkout master && git merge client\ngit checkout server && git rebase master\ngit checkout master && git merge server\n\nThe resulting repository is present in the attached archive in folder:\n./rebase-experiment/repo-after-rebases/\n\n== Expected result ==\n\nThe result I expected on the master branch after the rebases was:\n\nC1 -> c2 -> C3 -> C8 -> C9 -> C3 -> C4 -> C10 (with C3.txt present /\nreadded at the end)\n\nThe actual result present in ./rebase-experiment/repo-after-rebases/ is:\n\nC1 -> c2 -> C3 -> C8 -> C9 -> C4 -> C10 (with C3.txt not present / not\nreadded at the end)\n\n== Why did I expect that ==\n\nOf course after the client rebase, C3.txt should be gone (since it's\ngone at the original last commit of the client branch).\n\nBut since it still exists in the server branch at the final commit,\nafter rebasing & reapplying that onto the master, shouldn't it be put\nback in? Also, I would expect C3 -> C4 -> C10 as the complete chain of\ncommits of the remaining server branch to be attached at the end, not\njust C4 -> C10...\n\nDoes git somehow detect C3 would be applied twice? Doesn't the commit\nhash of C3 change after it is rebased? So how exactly would it figure\nthat out? I'm really unsure about what is going on.\n\nRegards,\nJonas Thiem\n"},{"id":"339131","messageId":"20180213003624.GC1022467@genre.crustytoothpaste.net","threadId":"47806","inReplyTo":"44e87a5a-b2be-f3f5-ac98-6831e056152d@thiem.email","subject":"Re: Question about rebasing - unexpected result, can't figure out why","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-13T00:36:25Z","receivedAt":"2018-02-13T00:36:39Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sat, Feb 10, 2018 at 09:47:57PM +0100, Jonas Thiem wrote:\n> == Why did I expect that ==\n> \n> Of course after the client rebase, C3.txt should be gone (since it's\n> gone at the original last commit of the client branch).\n> \n> But since it still exists in the server branch at the final commit,\n> after rebasing & reapplying that onto the master, shouldn't it be put\n> back in? Also, I would expect C3 -> C4 -> C10 as the complete chain of\n> commits of the remaining server branch to be attached at the end, not\n> just C4 -> C10...\n> \n> Does git somehow detect C3 would be applied twice? Doesn't the commit\n> hash of C3 change after it is rebased? So how exactly would it figure\n> that out? I'm really unsure about what is going on.\n\nYes.  The git rebase documentation says, \"Note that any commits in HEAD\nwhich introduce the same textual changes as a commit in HEAD..<upstream>\nare omitted (i.e., a patch already accepted upstream with a different\ncommit message or timestamp will be skipped).\"\n\nIf you want to be very explicit about replaying these commits, you can\nsay \"git rebase --onto master $(git merge-base master HEAD)\", in which\ncase C3 will be replayed.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"}]}