{"thread":{"id":"49446","subject":"--skip-worktree and operations like checkout / stash /etc.","startedAt":"2018-09-27T22:29:23Z","lastAt":"2018-09-28T13:36:09Z","messageCount":2,"participants":["Raman Gupta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"359155","messageId":"CADF5XCygzArjd9rgY_x_BqnhL5QpFL1CO1JjOHnBQc3HFn_JdQ@mail.gmail.com","threadId":"49446","inReplyTo":null,"subject":"--skip-worktree and operations like checkout / stash /etc.","fromName":"Raman Gupta","fromEmail":"rocketraman@gmail.com","sentAt":"2018-09-27T22:29:09Z","receivedAt":"2018-09-27T22:29:23Z","isPatch":false,"sender":{"key":"rocketraman@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53049?v=4"},"body":"The comand `update-index --skip-worktree` seems to be an ideal way to\ntell git to locally ignore some modified files. However, this seems\nnot to play well with very common commands like `checkout` and\n`stash`.\n\n$ git checkout other-branch\nerror: Your local changes to the following files would be overwritten\nby checkout:\n        path/to/ignored/file\nPlease commit your changes or stash them before you switch branches.\nAborting\n\nOk, well lets try stashing:\n\n$ git stash save\nNo local changes to save\n\nOk, lets try a checkout with a merge:\n\n$ git checkout -m other-branch\nerror: Entry 'path/to/ignored/file' not uptodate. Cannot merge.\n\nOk, lets force this sucker:\n\n$ git checkout -f other-branch\nerror: Entry 'path/to/ignored/file' not uptodate. Cannot merge.\n\nOk, at this point I'm wondering, do I really need to\n--no-skip-worktree all the ignored files, do my `checkout -m`, and\nthen ignore them again? Umm, no, that ain't gonna work.\n\nI'd love for git to just check if my worktree-skipped changes will\nmerge cleanly into the target branch, and if they do so, go ahead and\ndo that merge (with perhaps a notification printed to the console) and\nkeep the skip worktree status. If the merge ends up with a conflict,\nthen feel free to no-worktree-skip it and show me merge conflicts.\n\nRegards,\nRaman\n"},{"id":"359199","messageId":"CADF5XCxfmuqXau4YGrGgfU6JgxbHthZn5o5_t6J=x9JEaS_K4Q@mail.gmail.com","threadId":"49446","inReplyTo":"CADF5XCygzArjd9rgY_x_BqnhL5QpFL1CO1JjOHnBQc3HFn_JdQ@mail.gmail.com","subject":"Re: --skip-worktree and operations like checkout / stash /etc.","fromName":"Raman Gupta","fromEmail":"rocketraman@gmail.com","sentAt":"2018-09-28T13:35:55Z","receivedAt":"2018-09-28T13:36:09Z","isPatch":false,"sender":{"key":"rocketraman@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53049?v=4"},"body":"In the meantime I've created this simple script, but what a hack...\n\n#!/bin/bash\ngit ls-files -v | grep \"^S \" | cut -c3- | readarray ignored\nfor x in \"${ignored[@]}\"; do\n  git update-index --no-skip-worktree -- \"$x\"\ndone\ngit checkout -m $@\nfor x in \"${ignored[@]}\"; do\n  git update-index --skip-worktree -- \"$x\"\ndone\n\nRegards,\nRaman\nOn Thu, Sep 27, 2018 at 6:29 PM Raman Gupta <rocketraman@gmail.com> wrote:\n>\n> The comand `update-index --skip-worktree` seems to be an ideal way to\n> tell git to locally ignore some modified files. However, this seems\n> not to play well with very common commands like `checkout` and\n> `stash`.\n>\n> $ git checkout other-branch\n> error: Your local changes to the following files would be overwritten\n> by checkout:\n>         path/to/ignored/file\n> Please commit your changes or stash them before you switch branches.\n> Aborting\n>\n> Ok, well lets try stashing:\n>\n> $ git stash save\n> No local changes to save\n>\n> Ok, lets try a checkout with a merge:\n>\n> $ git checkout -m other-branch\n> error: Entry 'path/to/ignored/file' not uptodate. Cannot merge.\n>\n> Ok, lets force this sucker:\n>\n> $ git checkout -f other-branch\n> error: Entry 'path/to/ignored/file' not uptodate. Cannot merge.\n>\n> Ok, at this point I'm wondering, do I really need to\n> --no-skip-worktree all the ignored files, do my `checkout -m`, and\n> then ignore them again? Umm, no, that ain't gonna work.\n>\n> I'd love for git to just check if my worktree-skipped changes will\n> merge cleanly into the target branch, and if they do so, go ahead and\n> do that merge (with perhaps a notification printed to the console) and\n> keep the skip worktree status. If the merge ends up with a conflict,\n> then feel free to no-worktree-skip it and show me merge conflicts.\n>\n> Regards,\n> Raman\n"}]}