git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Is the entire working copy “at one branch”?

From
Stefan Monov <logixoul@gmail.com>
Date
Oct 31, 2016, 10:41 UTC
Message-ID
<CAJtFkWtsG9zRuL+BSTG-Wgjo+DZJpxobCXK94y-grgN7UTzULA@mail.gmail.com>
In-Reply-To
<CALhvvbYE6Tt3eByDVMB3a4t=nm3dScVZSea0Z1SsKVgwFSiQ-w@mail.gmail.com>
Thanks Alexei!
On Sat, Oct 29, 2016 at 12:47 PM, Alexei Lozovsky <a.lozovsky@gmail.com> wrote:
Show 60 quoted lines
> Hi Stefan,
>
> Generally with git, your entire working copy will have the same
> revision (set to current branch, aka HEAD). The idea behind this
> is that your working copy of a repository should always be in
> consistent state.
>
> You can check out specific files or directories from another
> revision (mimicking "svn update -r1234 filename"):
>
>     $ git checkout branch-or-sha-hash -- filename
>
> However, SVN tracks the 'revision' thing on per-file basis, while
> in git this is a property of the working copy. So if you do like
> above then git will be telling you that the 'filename' has been
> changed (as it is certainly different from its pristine version
> in HEAD):
>
>     $ git status
>     On branch master
>     Changes to be committed:
>       (use "git reset HEAD <file>..." to unstage)
>
>             modified:   filename
>
> So it's generally not recommended to do such a thing.
>
> Another thing that you _can do_ in git to mimick SVN is the
> 'standard layout'. There is a feature called "git worktree" which
> allows you to have SVN-like directory structure with multiple
> directories linked to different working copies:
>
>     $ mkdir my-project
>     $ cd my-project
>     $ git clone my-project-repository master
>     $ mkdir branches
>     $ cd master
>     $ git worktree add -b branch-1 ../branches/branch-1
>     $ git worktree add -b branch-2 ../branches/branch-2
>
> After that you will have directory structure like this:
>
>     $ tree my-project
>     my-project
>     ├── branches
>     │   ├── branch-1
>     │   │   ├── 1
>     │   │   ├── 2
>     │   │   └── 3
>     │   └── branch-2
>     │       ├── 1
>     │       ├── 2
>     │       └── banana
>     └── master
>         ├── 1
>         └── 2
> You can work with these working copies separately, like you
> would be working with SVN. Commits in 'master' will go to the
> 'master' branch, commits made in 'branches/branch-1' will go
> to the 'branch-1' branch.
Previous: Alexei Lozovsky
Message 3 of 3 in “Is the entire working copy “at one branch”?”
  1. Stefan MonovOct 28, 2016
  2. Alexei LozovskyOct 29, 2016
  3. Stefan MonovOct 31, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.