Single working branch with Git

前端 未结 7 1491
予麋鹿
予麋鹿 2021-01-01 15:21

Bounty short description

Is there a portable way to use a single repository w/ multiple checkouts? As an alternative to ha

7条回答
  •  臣服心动
    2021-01-01 15:44

    Actually, git-new-workdir was made for exactly this problem. I have the same problem, and use it without any issues. About your reservations:

    There is this script git-new-workdir that is supposed to allow multiple working branches, but for one, it is not part of the git release althoug it has been around for about 3 years, so I do not trust it to keep my files consistent.

    Well, I (and many others) have used it for years, and I have not come across any bugs myself, nor have I heard of any real problems (apart from a minor limitations, see below). That may not sound like much, but even with git itself (or any -free- SW project, for that matter), the only real guarantee you get is "no one has found a problem yet". I don't know why git-new-workdir is still in contrib, but I don't think that should deter you.

    And secondly, I cannot find it as part of the Windows distribution, which is one of the machines I use for development.

    That may just be because you distribution chose not to include the contrib/ stuff.

    If you use git under Cygwin, you can just download and use the original git-new-workdir script. It works fine, I use it myself. If you use msysGit, there are ports available: https://github.com/joero74/git-new-workdir/blob/master/git-new-workdir.cmd and https://github.com/dansmith65/git/blob/master/contrib/workdir/git-new-workdir-win . I don't know about their quality, though.

    Limitations of git-new-workdir

    Just for completeness' sake, here are the limitations I know of:

    • If you checkout the same branch in both working directories, and then commit something in one working directory, the state of the other will get confused: git-new-workdir: Commit in working tree A causes bogus changes in tree B
    • Apparently, you should not use git-new-workdir to copy a working directory already created by git-new-workdir. Just always copy the original clone. Actually, I believe recent versions of the script will detect this situation and error out.
    • git prune does not properly respect reflog entries

提交回复
热议问题