On Sat, Sep 20, 2014 at 10:41 PM, Duy Nguyen <pclouds@xxxxxxxxx> wrote: > On Thu, Sep 11, 2014 at 11:02:36AM -0400, Marc Branchaud wrote: >> Um, didn't you say in [1] that you'd use the text I posted in [2]? >> >> [1] http://article.gmane.org/gmane.comp.version-control.git/256446 >> [2] http://article.gmane.org/gmane.comp.version-control.git/256323 > > That's the problem with updating a bit one day and a bit another > day. Thanks for checking. Does this look ok? > > -- 8< -- > Subject: [PATCH] checkout: support checking out into a new working directory > > "git checkout --to" sets up a new working directory with a .git file > pointing to $GIT_DIR/worktrees/<id>. It then executes "git checkout" > again on the new worktree with the same arguments except "--to" is > taken out. The second checkout execution, which is not contaminated > with any info from the current repository, will actually check out and > everything that normal "git checkout" does. > > Helped-by: Marc Branchaud <marcnarc@xxxxxxxxxxx> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> > --- > diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt > index 33ad2ad..c101575 100644 > --- a/Documentation/git-checkout.txt > +++ b/Documentation/git-checkout.txt > @@ -388,6 +395,45 @@ $ git reflog -2 HEAD # or > $ git log -g -2 HEAD > ------------ > > +MULTIPLE WORKING TREES > +---------------------- > + > +A git repository can support multiple working trees, allowing you to check > +out more than one branch at a time. With `git checkout --to` a new working > +tree is associated with the repository. This new working tree is called a > +"linked working tree" as opposed to the "main working tree" prepared by "git > +init" or "git clone". A repository has one main working tree (if it's not a > +bare repository) and zero or more linked working trees. > + > +Each linked working tree has a private sub-directory in the repository's > +$GIT_DIR/worktrees directory. The private sub-directory's name is usually > +the base name of the linked working tree's path, possibly appended with a > +number to make it unique. For example, when `$GIT_DIR=/path/main/.git` the > +command `git checkout --to /path/other/test-next next` creates the linked > +working tree in `/path/other/test-next` and also creates a > +`$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1` > +if `test-next` is already taken). > + > +Within a linked working tree, $GIT_DIR is set to point to this private > +directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and > +$GIT_COMMON_DIR is set to point back to the main working tree's $GIT_DIR > +(e.g. `/path/main/.git`). These settings are made in a `.git` file located at > +the top directory of the linked working tree. > + > +Path resolution via `git rev-parse --git-path` uses either > +$GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, in the > +linked working tree `git rev-parse --git-path HEAD` returns > +`/path/main/.git/worktrees/test-next/HEAD` (not > +`/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git > +rev-parse --git-path refs/heads/master` uses > +$GIT_COMMON_DIR and returns `/path/main/.git/refs/heads/master`, > +since refs are shared across all working trees. > + > +See linkgit:gitrepository-layout[5] for more information. The rule of > +thumb is do not make any assumption about whether a path belongs to > +$GIT_DIR or $GIT_COMMON_DIR when you need to directly access something > +inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. Would it make sense for this "rule of thumb" summary to be presented first, and then the explanation of that rule after, rather than the reverse as is currently the case? > diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh > new file mode 100755 > index 0000000..8c73b18 > --- /dev/null > +++ b/t/t2025-checkout-to.sh > @@ -0,0 +1,63 @@ > +test_expect_success 'checkout --to from a linked checkout' ' > + ( > + cd here && > + git checkout --to nested-here master Broken &&-chain. > + cd nested-here && > + git fsck > + ) > +' > + > +test_expect_success 'checkout --to a new worktree creating new branch' ' > + git checkout --to there -b newmaster master && > + ( > + cd there && > + test_cmp ../init.t init.t && > + git symbolic-ref HEAD >actual && > + echo refs/heads/newmaster >expect && > + test_cmp expect actual && > + git fsck > + ) > +' > + > +test_done > -- > 2.1.0.rc0.78.gc0d8480 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html