{"thread":{"id":"42092","subject":"Is there a \"git reset --keep <sha1> || git reset --hard <sha1>\" alternative?","startedAt":"2016-04-20T17:18:14Z","lastAt":"2016-04-20T20:28:44Z","messageCount":3,"participants":["Ævar Arnfjörð Bjarmason","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"283969","messageId":"CACBZZX6k6sFv2GWOzu0Ow1T+5ci2gmMOvaD37bvbm1_qfetr8Q@mail.gmail.com","threadId":"42092","inReplyTo":null,"subject":"Is there a \"git reset --keep <sha1> || git reset --hard <sha1>\" alternative?","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-20T17:18:14Z","receivedAt":"2016-04-20T17:18:14Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"If you check out a git repository and chmod a checked-in file there\nthere away from git defaults then \"git reset --hard\" will re-chmod it.\n\nThe use-case for not having this happen is if you e.g. have some\ninotify thing or a stat() loop monitoring changes to the files, and\nyou'd like them to fire on \"real\" updates, not just updates that were\nintroduced because something re-chmoded a file.\n\nE.g. on current git.git master:\n\n    $ ls -l INSTALL ; chmod 600 INSTALL ; git reset --hard @{u} ; ls -l INSTALL\n    -rw-r--r-- 1 avar avar 9147 Apr 20 17:11 INSTALL\n    HEAD is now at e6ac6e1 Fifth batch for post 2.8 cycle\n    -rw-r--r-- 1 avar avar 9147 Apr 20 17:12 INSTALL\n\nWhat I'd like is for the permissions not to be altered:\n\n    $ ls -l INSTALL ; chmod 600 INSTALL ; git reset --keep @{u} ; ls -l INSTALL\n    -rw-r--r-- 1 avar avar 9147 Apr 20 17:12 INSTALL\n    -rw------- 1 avar avar 9147 Apr 20 17:12 INSTALL\n\nBut I don't want this to happen:\n\n    $ echo \"Blah\" > INSTALL && git add INSTALL && git commit -m\"blah\"\n    [master d29463e] blah\n     1 file changed, 1 insertion(+), 223 deletions(-)\n     rewrite INSTALL (100%)\n    $ ls -l INSTALL ; chmod 600 INSTALL ; git reset --keep @{u} ; ls -l INSTALL\n    -rw------- 1 avar avar 5 Apr 20 17:14 INSTALL\n    error: Entry 'INSTALL' not uptodate. Cannot merge.\n    fatal: Could not reset index file to revision '@{u}'.\n    -rw------- 1 avar avar 5 Apr 20 17:14 INSTALL\n\nInstead I want:\n\n    $ ls -l INSTALL ; chmod 600 INSTALL ; git reset --keep @{u} || git\nreset --hard @{u}  ; ls -l INSTALL\n    -rw------- 1 avar avar 5 Apr 20 17:14 INSTALL\n    error: Entry 'INSTALL' not uptodate. Cannot merge.\n    fatal: Could not reset index file to revision '@{u}'.\n    HEAD is now at e6ac6e1 Fifth batch for post 2.8 cycle\n    -rw-r--r-- 1 avar avar 9147 Apr 20 17:15 INSTALL\n\nAnd the expectation here is that I'll have something that does a chmod\nafter the reset happens, which is fine because we had a \"real\" change,\nI just don't want the repo to keep having flip-flopping permissions\nbecause I'd both like:\n\n * Local chmod to be respected\n * Actual file content changes to be wiped away by reset --hard\n\nIs there another way to do this, or dare I say alternatively maybe we\ncould use another option to reset making it even more confusing :)\n"},{"id":"283981","messageId":"xmqqvb3cumpd.fsf@gitster.mtv.corp.google.com","threadId":"42092","inReplyTo":"CACBZZX6k6sFv2GWOzu0Ow1T+5ci2gmMOvaD37bvbm1_qfetr8Q@mail.gmail.com","subject":"Re: Is there a \"git reset --keep <sha1> || git reset --hard <sha1>\" alternative?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-20T19:03:42Z","receivedAt":"2016-04-20T19:03:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n>     $ ls -l INSTALL ; chmod 600 INSTALL ; git reset --hard @{u} ; ls -l INSTALL\n>     -rw-r--r-- 1 avar avar 9147 Apr 20 17:11 INSTALL\n>     HEAD is now at e6ac6e1 Fifth batch for post 2.8 cycle\n>     -rw-r--r-- 1 avar avar 9147 Apr 20 17:12 INSTALL\n\nA quick question.  What happens when you did this instead?\n\n\tchmod 600 INSTALL\n        git update-index --refresh\n        git reset --hard\n\nDoes it match what you want to see?\n\nThe reason I ask is because I recall making a deliberate design\ndecision around this area.\n"},{"id":"283995","messageId":"CACBZZX7ELH+5fzkRiZBNyWDwpQgzpEGi15XGz21nQQFh5hiG1g@mail.gmail.com","threadId":"42092","inReplyTo":"xmqqvb3cumpd.fsf@gitster.mtv.corp.google.com","subject":"Re: Is there a \"git reset --keep <sha1> || git reset --hard <sha1>\" alternative?","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-20T20:28:44Z","receivedAt":"2016-04-20T20:28:44Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Wed, Apr 20, 2016 at 9:03 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n>\n>>     $ ls -l INSTALL ; chmod 600 INSTALL ; git reset --hard @{u} ; ls -l INSTALL\n>>     -rw-r--r-- 1 avar avar 9147 Apr 20 17:11 INSTALL\n>>     HEAD is now at e6ac6e1 Fifth batch for post 2.8 cycle\n>>     -rw-r--r-- 1 avar avar 9147 Apr 20 17:12 INSTALL\n>\n> A quick question.  What happens when you did this instead?\n>\n>         chmod 600 INSTALL\n>         git update-index --refresh\n>         git reset --hard\n>\n> Does it match what you want to see?\n>\n> The reason I ask is because I recall making a deliberate design\n> decision around this area.\n\nThe --hard doesn't wipe away the chmod, makes sense:\n\n    $ ls -l INSTALL ; chmod 600 INSTALL ; git update-index --refresh;\ngit reset --hard @{u} ; ls -l INSTALL\n    -rw-r--r-- 1 avar avar 9147 Apr 20 22:27 INSTALL\n    HEAD is now at 05045e0 tracing\n    -rw------- 1 avar avar 9147 Apr 20 22:27 INSTALL\n"}]}