{"thread":{"id":"44391","subject":"Is the entire working copy “at one branch”?","startedAt":"2016-10-28T15:01:34Z","lastAt":"2016-10-31T10:42:02Z","messageCount":3,"participants":["Stefan Monov","Alexei Lozovsky"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"305062","messageId":"CAJtFkWs4qYCqnbJD+zCRCAW3teczb4CdvncvYoMN_VvthJGr=w@mail.gmail.com","threadId":"44391","inReplyTo":null,"subject":"Is the entire working copy “at one branch”?","fromName":"Stefan Monov","fromEmail":"logixoul@gmail.com","sentAt":"2016-10-28T15:01:06Z","receivedAt":"2016-10-28T15:01:34Z","isPatch":false,"sender":{"key":"logixoul@gmail.com","avatar":"https://gravatar.com/avatar/225c01274d1ead9f204fb7d8b871a9aad653bd3d80dd4356efc8c83fdbc750e4?d=mp&s=160"},"body":"This is a very basic question but maybe I just don't know how to\nphrase my query well enough to find an answer.\n\nLet me begin with a SVN example. SVN doesn't have a \"current branch\"\nas a property of a working copy, so I'll give the example with\nrevisions instead. Consider a working copy with the dirs `foo` and\n`bar` in it. In SVN one can `update` foo to an earlier version, but\nkeep `bar` at `HEAD`.\n\nIs it possible in an analogical git working copy to checkout one\nbranch in dir `foo` without changing the branch checked out in `bar`?\n\nIf not, why not?\n\nTIA,\nStefan Monov\n"},{"id":"305159","messageId":"CALhvvbYE6Tt3eByDVMB3a4t=nm3dScVZSea0Z1SsKVgwFSiQ-w@mail.gmail.com","threadId":"44391","inReplyTo":"CAJtFkWs4qYCqnbJD+zCRCAW3teczb4CdvncvYoMN_VvthJGr=w@mail.gmail.com","subject":"Re: Is the entire working copy “at one branch”?","fromName":"Alexei Lozovsky","fromEmail":"a.lozovsky@gmail.com","sentAt":"2016-10-29T09:47:06Z","receivedAt":"2016-10-29T09:47:32Z","isPatch":false,"sender":{"key":"a.lozovsky@gmail.com","avatar":"https://gravatar.com/avatar/8bb8ff5ec366dd64bd8e08f768082934513da367ae047bcb0039292e4ed6bda5?d=mp&s=160"},"body":"Hi Stefan,\n\nGenerally with git, your entire working copy will have the same\nrevision (set to current branch, aka HEAD). The idea behind this\nis that your working copy of a repository should always be in\nconsistent state.\n\nYou can check out specific files or directories from another\nrevision (mimicking \"svn update -r1234 filename\"):\n\n    $ git checkout branch-or-sha-hash -- filename\n\nHowever, SVN tracks the 'revision' thing on per-file basis, while\nin git this is a property of the working copy. So if you do like\nabove then git will be telling you that the 'filename' has been\nchanged (as it is certainly different from its pristine version\nin HEAD):\n\n    $ git status\n    On branch master\n    Changes to be committed:\n      (use \"git reset HEAD <file>...\" to unstage)\n\n            modified:   filename\n\nSo it's generally not recommended to do such a thing.\n\nAnother thing that you _can do_ in git to mimick SVN is the\n'standard layout'. There is a feature called \"git worktree\" which\nallows you to have SVN-like directory structure with multiple\ndirectories linked to different working copies:\n\n    $ mkdir my-project\n    $ cd my-project\n    $ git clone my-project-repository master\n    $ mkdir branches\n    $ cd master\n    $ git worktree add -b branch-1 ../branches/branch-1\n    $ git worktree add -b branch-2 ../branches/branch-2\n\nAfter that you will have directory structure like this:\n\n    $ tree my-project\n    my-project\n    ├── branches\n    │   ├── branch-1\n    │   │   ├── 1\n    │   │   ├── 2\n    │   │   └── 3\n    │   └── branch-2\n    │       ├── 1\n    │       ├── 2\n    │       └── banana\n    └── master\n        ├── 1\n        └── 2\nYou can work with these working copies separately, like you\nwould be working with SVN. Commits in 'master' will go to the\n'master' branch, commits made in 'branches/branch-1' will go\nto the 'branch-1' branch.\n"},{"id":"305195","messageId":"CAJtFkWtsG9zRuL+BSTG-Wgjo+DZJpxobCXK94y-grgN7UTzULA@mail.gmail.com","threadId":"44391","inReplyTo":"CALhvvbYE6Tt3eByDVMB3a4t=nm3dScVZSea0Z1SsKVgwFSiQ-w@mail.gmail.com","subject":"Re: Is the entire working copy “at one branch”?","fromName":"Stefan Monov","fromEmail":"logixoul@gmail.com","sentAt":"2016-10-31T10:41:36Z","receivedAt":"2016-10-31T10:42:02Z","isPatch":false,"sender":{"key":"logixoul@gmail.com","avatar":"https://gravatar.com/avatar/225c01274d1ead9f204fb7d8b871a9aad653bd3d80dd4356efc8c83fdbc750e4?d=mp&s=160"},"body":"Thanks Alexei!\n\nOn Sat, Oct 29, 2016 at 12:47 PM, Alexei Lozovsky <a.lozovsky@gmail.com> wrote:\n> Hi Stefan,\n>\n> Generally with git, your entire working copy will have the same\n> revision (set to current branch, aka HEAD). The idea behind this\n> is that your working copy of a repository should always be in\n> consistent state.\n>\n> You can check out specific files or directories from another\n> revision (mimicking \"svn update -r1234 filename\"):\n>\n>     $ git checkout branch-or-sha-hash -- filename\n>\n> However, SVN tracks the 'revision' thing on per-file basis, while\n> in git this is a property of the working copy. So if you do like\n> above then git will be telling you that the 'filename' has been\n> changed (as it is certainly different from its pristine version\n> in HEAD):\n>\n>     $ git status\n>     On branch master\n>     Changes to be committed:\n>       (use \"git reset HEAD <file>...\" to unstage)\n>\n>             modified:   filename\n>\n> So it's generally not recommended to do such a thing.\n>\n> Another thing that you _can do_ in git to mimick SVN is the\n> 'standard layout'. There is a feature called \"git worktree\" which\n> allows you to have SVN-like directory structure with multiple\n> directories linked to different working copies:\n>\n>     $ mkdir my-project\n>     $ cd my-project\n>     $ git clone my-project-repository master\n>     $ mkdir branches\n>     $ cd master\n>     $ git worktree add -b branch-1 ../branches/branch-1\n>     $ git worktree add -b branch-2 ../branches/branch-2\n>\n> After that you will have directory structure like this:\n>\n>     $ tree my-project\n>     my-project\n>     ├── branches\n>     │   ├── branch-1\n>     │   │   ├── 1\n>     │   │   ├── 2\n>     │   │   └── 3\n>     │   └── branch-2\n>     │       ├── 1\n>     │       ├── 2\n>     │       └── banana\n>     └── master\n>         ├── 1\n>         └── 2\n> You can work with these working copies separately, like you\n> would be working with SVN. Commits in 'master' will go to the\n> 'master' branch, commits made in 'branches/branch-1' will go\n> to the 'branch-1' branch.\n"}]}