{"thread":{"id":"44357","subject":"Stash pop/apply conflict and --theirs and --ours","startedAt":"2016-10-22T23:05:34Z","lastAt":"2016-10-23T09:30:40Z","messageCount":2,"participants":["Sven Strickroth","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"304684","messageId":"169639c9-054f-8f4c-26bd-3f130fa4c1ee@cs-ware.de","threadId":"44357","inReplyTo":null,"subject":"Stash pop/apply conflict and --theirs and --ours","fromName":"Sven Strickroth","fromEmail":"sven@cs-ware.de","sentAt":"2016-10-22T22:58:12Z","receivedAt":"2016-10-22T23:05:34Z","isPatch":false,"sender":{"key":"sven@cs-ware.de","avatar":null},"body":"Hi,\n\nI regularly experience that beginners have problems unterstanding that\n--ours and --theirs are swapped when a conflict occurrs on git stash\napply or stash pop.\n\nFrom the HCI perspective this is really counter intuitive.\n\nSo, I'd like to propose that on git shash pop/apply theirs and ours\nshould be swapped in git index, so that git checkout --theirs and --ours\nwork as expected.\n\nPS: I'm sorry if this was already discussed, I haven't found any discussion.\n\n-- \nBest regards,\n Sven Strickroth\n PGP key id F5A9D4C4 @ any key-server\n"},{"id":"304750","messageId":"20161023093032.iahc3itg6a5rqtdf@sigill.intra.peff.net","threadId":"44357","inReplyTo":"169639c9-054f-8f4c-26bd-3f130fa4c1ee@cs-ware.de","subject":"Re: Stash pop/apply conflict and --theirs and --ours","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-10-23T09:30:32Z","receivedAt":"2016-10-23T09:30:40Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Oct 23, 2016 at 12:58:12AM +0200, Sven Strickroth wrote:\n\n> I regularly experience that beginners have problems unterstanding that\n> --ours and --theirs are swapped when a conflict occurrs on git stash\n> apply or stash pop.\n> \n> From the HCI perspective this is really counter intuitive.\n\nI know that people have complained about \"rebase\" swapping the two, but\nI don't think anybody has ever mentioned it for stash. I'm not sure I\nthat they are swapped, though.\n\nThe \"ours\" content is generally what was in the HEAD before the\noperation started, and \"theirs\" is what the operation is bringing into\nthat history. That is true of \"merge\" and \"cherry-pick\". And AFAICT, it\nis true of \"stash\", too (I basically think of \"stash apply\" as a\ncherry-pick).\n\nSo with a setup like:\n\n  git init\n  echo base >file\n  git add file\n  git commit -m file\n\n  echo stash >file\n  git stash\n\n  echo master >file\n  git commit -am master\n\n  git checkout -b branch HEAD^\n  echo branch >file\n  git commit -am branch\n\nif we merge, then --theirs is the branch we are merging:\n\n  git checkout master\n  git merge branch\n  git checkout --theirs file\n  cat file\n  # \"branch\"\n\nLikewise, if we cherry-pick:\n\n  git reset --hard\n  git cherry-pick branch\n  git checkout --theirs file\n  cat file\n  # \"branch\"\n\nAnd likewise if we apply the stash:\n\n  git reset --hard\n  git stash apply\n  git checkout --theirs file\n  cat file\n  # \"stash\"\n\nSo that seems consistent to me.\n\nI guess if you are stashing in order to pull somebody else's work, like:\n\n  git stash\n  git pull\n  git stash pop\n\nthen conceptually the stash is \"ours\" and HEAD is \"theirs\". This is\nexactly like the rebase case. E.g., if you instead did:\n\n  git commit -m 'tmp stash'\n  git pull --rebase\n\nSo I sympathize, but I don't think that having \"stash\" flip the order\nwould be the right thing to do in all cases. In theory there could be\nsome kind of option (and things like pull autostash could use it), but I\nsuspect it may be hard to implement in practice. The unpack-trees code\ndoes not treat \"ours\" and \"theirs\" entirely symmetrically (the \"ours\"\nside represents the current working tree, so we might do things like\ncheck whether the index is fresh). I guess you could flip the \"1\" and\n\"2\" bits in the index after the conflicted merge completes.\n\nI'm still not convinced it's a good idea, though.\n\n-Peff\n"}]}