{"thread":{"id":"31721","subject":"git reset respect remote repo (make git idiot proof)","startedAt":"2012-10-03T14:49:06Z","lastAt":"2012-10-05T05:35:08Z","messageCount":9,"participants":["Geoffrey De Smet","Ramkumar Ramachandra","Phil Hord","Andreas Schwab","Junio C Hamano","Dirk Heinrichs"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"200424","messageId":"k4hj91$4tt$4@ger.gmane.org","threadId":"31721","inReplyTo":null,"subject":"git reset respect remote repo (make git idiot proof)","fromName":"Geoffrey De Smet","fromEmail":"ge0ffrey.spam@gmail.com","sentAt":"2012-10-03T14:49:06Z","receivedAt":"2012-10-03T14:49:06Z","isPatch":false,"sender":{"key":"ge0ffrey.spam@gmail.com","avatar":"https://gravatar.com/avatar/e175aac75520b39e51746c4215362c7d9b1fad01691447651233a572e496d346?d=mp&s=160"},"body":"Suppose this case:\n\ngit clone .../blessedRepo.git\n// do changes\ngit commit -m\"bad1\"\n// do changes\ngit commit -m\"bad2\"\ngit reset --hard HEAD^4 // Why does it let me do this?\n\n// I just \"broke\" my local repository, because if I continue\n\n// do changes\ngit commit -m\"good1\"\ngit push origin master // fails because the history disrespects the \nremote repo's history\n\nThe following commands are ok to do (because I have 2 unpushed commits):\n  git reset --hard^1\n  git reset --hard^2\nbut these are not and should be prevented (unless forced):\n  git reset --hard^3\n  git reset --hard^4\n\n\nIs there any way to make git idiot proof by enabling that the local repo \nshould always respect the history of the remote repo (unless forced)?\nIs there any way to make this a default for anyone who clones our \nblessed repo?\nNo one that clones our blessed repo wants to come into the situation \nabove. And if they do, they can always force it.\n"},{"id":"200426","messageId":"CALkWK0mP36OXZ7kXZnA-KH3HB2mCLJuvx6iX2=LQawSCgM-ujA@mail.gmail.com","threadId":"31721","inReplyTo":"k4hj91$4tt$4@ger.gmane.org","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2012-10-03T14:59:48Z","receivedAt":"2012-10-03T14:59:48Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Geoffrey,\n\nGeoffrey De Smet wrote:\n> [...]\n> The following commands are ok to do (because I have 2 unpushed commits):\n>  git reset --hard^1\n>  git reset --hard^2\n> but these are not and should be prevented (unless forced):\n>  git reset --hard^3\n>  git reset --hard^4\n>\n>\n> Is there any way to make git idiot proof by enabling that the local repo\n> should always respect the history of the remote repo (unless forced)?\n> Is there any way to make this a default for anyone who clones our blessed\n> repo?\n> No one that clones our blessed repo wants to come into the situation above.\n> And if they do, they can always force it.\n\nThis makes little sense.\nWhich remote?  What if I have multiple remotes?  Which branch? (Many\nof my branches are behind `master`).  What if I want different\nhistories on different remotes?  What about more advanced operations\nwhich implicitly 'reset' like rebase?  What if I want to rewrite\nhistory?\n\nRam\n"},{"id":"200427","messageId":"k4hkl1$jag$1@ger.gmane.org","threadId":"31721","inReplyTo":"CALkWK0mP36OXZ7kXZnA-KH3HB2mCLJuvx6iX2=LQawSCgM-ujA@mail.gmail.com","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Geoffrey De Smet","fromEmail":"ge0ffrey.spam@gmail.com","sentAt":"2012-10-03T15:12:34Z","receivedAt":"2012-10-03T15:12:34Z","isPatch":false,"sender":{"key":"ge0ffrey.spam@gmail.com","avatar":"https://gravatar.com/avatar/e175aac75520b39e51746c4215362c7d9b1fad01691447651233a572e496d346?d=mp&s=160"},"body":"\nOp 03-10-12 16:59, Ramkumar Ramachandra schreef:\n> Hi Geoffrey,\n>\n> Geoffrey De Smet wrote:\n>> [...]\n>> The following commands are ok to do (because I have 2 unpushed commits):\n>>   git reset --hard^1\n>>   git reset --hard^2\n>> but these are not and should be prevented (unless forced):\n>>   git reset --hard^3\n>>   git reset --hard^4\n>>\n>>\n>> Is there any way to make git idiot proof by enabling that the local repo\n>> should always respect the history of the remote repo (unless forced)?\n>> Is there any way to make this a default for anyone who clones our \n>> blessed\n>> repo?\n>> No one that clones our blessed repo wants to come into the situation \n>> above.\n>> And if they do, they can always force it.\n> This makes little sense.\n> Which remote?\nTo all remotes which have a relationship to this repo with the \n-respectRemote flag.\nNormally, only the blessed remote will have this.\n> What if I have multiple remotes?  Which branch? (Many\n> of my branches are behind `master`).\nEverytime a branch merges or rebases with a remote repository, it's \nflags the last commit of that remote repository as the pointOfNoReset \ncommit.\nIf local branches merge or rebase with a local branch, the \npointOfNoReset commit is transitively applied (only the last one wins).\ngit reset will fail to reset beyond the pointOfNoReset commit, unless \nforced.\n\nBranches that are behind master, will have a pointOfNoReset commit in \ntheir history, if master goes forward afterwards, that won't affect \nthose branches, not until they are merged.\n>    What if I want different\n> histories on different remotes?\nDon't use the -respectRemote flag in the relationship between those 2 \nrepo's.\n>   What about more advanced operations\n> which implicitly 'reset' like rebase?\nThem too. All operations would need to follow the -respectRemote flag's \nlimitations, unless forced.\n>    What if I want to rewrite\n> history?\nDon't use the -respectRemote flag in the relationship between this repo \nand any other repo.\nOr force it.\n>\n> Ram\n"},{"id":"200432","messageId":"CABURp0qVWg2PvD4PcjJ9q45x9WxJCuJEQL8Rze=qerWXg72Txw@mail.gmail.com","threadId":"31721","inReplyTo":"k4hj91$4tt$4@ger.gmane.org","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2012-10-03T16:40:00Z","receivedAt":"2012-10-03T16:40:00Z","isPatch":false,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Wed, Oct 3, 2012 at 10:49 AM, Geoffrey De Smet\n<ge0ffrey.spam@gmail.com> wrote:\n> Suppose this case:\n>\n> git clone .../blessedRepo.git\n> // do changes\n> git commit -m\"bad1\"\n> // do changes\n> git commit -m\"bad2\"\n> git reset --hard HEAD^4 // Why does it let me do this?\n>\n> // I just \"broke\" my local repository, because if I continue\n>\n> // do changes\n> git commit -m\"good1\"\n> git push origin master // fails because the history disrespects the remote\n> repo's history\n>\n> The following commands are ok to do (because I have 2 unpushed commits):\n>  git reset --hard^1\n>  git reset --hard^2\n> but these are not and should be prevented (unless forced):\n>  git reset --hard^3\n>  git reset --hard^4\n>\n>\n> Is there any way to make git idiot proof by enabling that the local repo\n> should always respect the history of the remote repo (unless forced)?\n> Is there any way to make this a default for anyone who clones our blessed\n> repo?\n\nI suppose if we go down this path we must also prevent users from\nhaving any local branches whose names match those used on the remote\nunless the remote branches are also ancestors of our local branch.\nBut then we may get into trouble when we pull new branches which now\nconflict but previously did not.\n\nI'm afraid this is a Pandora's box of woes.\n\nBut I feel your pain.  I think the solution lies in relegating 'reset'\nto the plumbing or the power-user realm of commands since I feel it is\nquite overloaded and sometimes dangerous.  There was a thread some\nmonths back heading in this direction, but I failed to keep it going.\n\n    http://comments.gmane.org/gmane.comp.version-control.git/185825\n\n\nPhil\n"},{"id":"200434","messageId":"m2bogja46v.fsf@igel.home","threadId":"31721","inReplyTo":"k4hj91$4tt$4@ger.gmane.org","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2012-10-03T16:52:24Z","receivedAt":"2012-10-03T16:52:24Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Geoffrey De Smet <ge0ffrey.spam@gmail.com> writes:\n\n> Suppose this case:\n>\n> git clone .../blessedRepo.git\n> // do changes\n> git commit -m\"bad1\"\n> // do changes\n> git commit -m\"bad2\"\n> git reset --hard HEAD^4 // Why does it let me do this?\n\nBecause there is nothing wrong with that.\n\n> // I just \"broke\" my local repository, because if I continue\n\nNo you didn't.\n\n> // do changes\n> git commit -m\"good1\"\n> git push origin master // fails because the history disrespects the remote\n> repo's history\n\nYou may just as well want to push it to a different branch (or even a\ndifferent repository).\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"200580","messageId":"k4jiv4$5k9$1@ger.gmane.org","threadId":"31721","inReplyTo":"m2bogja46v.fsf@igel.home","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Geoffrey De Smet","fromEmail":"ge0ffrey.spam@gmail.com","sentAt":"2012-10-04T08:56:04Z","receivedAt":"2012-10-04T08:56:04Z","isPatch":false,"sender":{"key":"ge0ffrey.spam@gmail.com","avatar":"https://gravatar.com/avatar/e175aac75520b39e51746c4215362c7d9b1fad01691447651233a572e496d346?d=mp&s=160"},"body":"\nOp 03-10-12 18:52, Andreas Schwab schreef:\n> Geoffrey De Smet <ge0ffrey.spam@gmail.com> writes:\n>\n>> Suppose this case:\n>>\n>> git clone .../blessedRepo.git\n>> // do changes\n>> git commit -m\"bad1\"\n>> // do changes\n>> git commit -m\"bad2\"\n>> git reset --hard HEAD^4 // Why does it let me do this?\n> Because there is nothing wrong with that.\n>\n>> // I just \"broke\" my local repository, because if I continue\n> No you didn't.\n>\n>> // do changes\n>> git commit -m\"good1\"\n>> git push origin master // fails because the history disrespects the remote\n>> repo's history\n> You may just as well want to push it to a different branch (or even a\n> different repository).\nIn most cases (probably more than 90%?), the developer will want to get \nhis changes into the remote branch where it came from.\n\nWhat do you think of the -respectRepository flag idea? If you want to \npush to different branches/repo's you can not use it, turn it off or \n-force those commands.\n\nA remote repository can be optionally flagged with -respectRepository.\nThat means that git should prevent the user from making local changes in \nthe history that will prevent a normal push to that remote repository.\n\nIf a remote repository is flagged as such, git keeps track of a \n\"pointOfNoReset\" commit:\nEvery time a branch merges or rebases with a remote repository, it's \nflags the last commit of that remote repository as the pointOfNoReset \ncommit.\nIf local branches merge or rebase with a local branch, the \npointOfNoReset commit is transitively applied (only the last one wins).\ngit reset will fail to reset beyond the pointOfNoReset commit, unless \nforced.\ngit rebase and other git commands will also fail accordingly, unless forced.\n\n>\n> Andreas.\n>\n"},{"id":"200581","messageId":"k4jj5n$72b$1@ger.gmane.org","threadId":"31721","inReplyTo":"CABURp0qVWg2PvD4PcjJ9q45x9WxJCuJEQL8Rze=qerWXg72Txw@mail.gmail.com","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Geoffrey De Smet","fromEmail":"ge0ffrey.spam@gmail.com","sentAt":"2012-10-04T08:59:36Z","receivedAt":"2012-10-04T08:59:36Z","isPatch":false,"sender":{"key":"ge0ffrey.spam@gmail.com","avatar":"https://gravatar.com/avatar/e175aac75520b39e51746c4215362c7d9b1fad01691447651233a572e496d346?d=mp&s=160"},"body":"\nOp 03-10-12 18:40, Phil Hord schreef:\n> But I feel your pain.  I think the solution lies in relegating 'reset'\n> to the plumbing or the power-user realm of commands since I feel it is\n> quite overloaded and sometimes dangerous.  There was a thread some\n> months back heading in this direction, but I failed to keep it going.\n>\n>      http://comments.gmane.org/gmane.comp.version-control.git/185825\n\nI personally use git reset a lot:\n- Try an experiment\n- Commit a few commits as the experiment progresses\n- figure out that the experiment is a dead end\n- git reset all those _local_ commits\n\nThe point is: they are local commits, so no harm done.\nBut there's nothing preventing me from resetting pushed commits too, \nwhich would mean harm.\n"},{"id":"200586","messageId":"7vsj9tvci0.fsf@alter.siamese.dyndns.org","threadId":"31721","inReplyTo":"k4jj5n$72b$1@ger.gmane.org","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-05T03:11:51Z","receivedAt":"2012-10-05T03:11:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Geoffrey De Smet <ge0ffrey.spam@gmail.com> writes:\n\n> Op 03-10-12 18:40, Phil Hord schreef:\n>> But I feel your pain.  I think the solution lies in relegating 'reset'\n>> to the plumbing or the power-user realm of commands since I feel it is\n>> quite overloaded and sometimes dangerous.  There was a thread some\n>> months back heading in this direction, but I failed to keep it going.\n>>\n>>      http://comments.gmane.org/gmane.comp.version-control.git/185825\n>\n> I personally use git reset a lot:\n> - Try an experiment\n> - Commit a few commits as the experiment progresses\n> - figure out that the experiment is a dead end\n> - git reset all those _local_ commits\n>\n> The point is: they are local commits, so no harm done.\n> But there's nothing preventing me from resetting pushed commits too,\n> which would mean harm.\n\nEven if you reset your local branch beyond the point you pushed out,\nno harm is caused, as \"git push\" will catch that mistake, e.g.\n\n\t: on 'master' that integrates with 'master' at remote\n\t$ git reset --hard HEAD~4\n        : work work work and commit commit commit\n        $ git push origin master\n        ... will result in refusal due to non-fast-forward\n\nAnd then you can recover from it easily; one workflow may go like\nthis:\n\n\t: update refs/remotes/origin/master, among other things\n\t$ git fetch origin\n        : recover the \"work work ... commit commit\" part\n        $ git rebase origin/master\n\nAnother thing we could think about doing is to warn at the point you\nreset your head away.  The above \"reset --hard HEAD~4\", before doing\nwhat it was told to do, could perform:\n\n\tgit rev-list HEAD~4..HEAD\n\n(replace \"HEAD~4\" with whereever you are attempting to go) and see\nif any of the listed commits is an ancestor of @{upstream} of the\ncurrent branch.  And if that is true, then your updated \"reset\" can\nissue a warning, just like \"git checkout branchname\" to leave the\ndetached HEAD state gives you a friendly warning.\n"},{"id":"200589","messageId":"1611434.pfF2lutBRf@moria","threadId":"31721","inReplyTo":"k4jj5n$72b$1@ger.gmane.org","subject":"Re: git reset respect remote repo (make git idiot proof)","fromName":"Dirk Heinrichs","fromEmail":"dirk.heinrichs@altum.de","sentAt":"2012-10-05T05:35:08Z","receivedAt":"2012-10-05T05:35:08Z","isPatch":false,"sender":{"key":"dirk.heinrichs@altum.de","avatar":null},"body":"Am Donnerstag 04 Oktober 2012, 10:59:36 schrieb Geoffrey De Smet:\n\n> I personally use git reset a lot:\n> - Try an experiment\n> - Commit a few commits as the experiment progresses\n> - figure out that the experiment is a dead end\n> - git reset all those local commits\n\nHmm, what if you do your experiments on a dedicated branch? Branch deletion is \n\"push-save\", isn't it?\n\nBye...\n\n\tDirk\n-- \nDirk Heinrichs <dirk.heinrichs@altum.de>\nTel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913\nGPG Public Key C2E467BB | Jabber: dirk.heinrichs@altum.de\n"}]}