- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当我这样做时 git worktree list
,显示如下。
/path/to/workspace c943d35 [master]
/path/to/workspace ef4df56 (detached HEAD)
git worktree prune
,但它不会改变任何东西。任何帮助将不胜感激。非常感谢。
最佳答案
Each linked working tree has a private sub-directory in the repository’s
$GIT_DIR/worktrees
directory.
main repo/.git/worktrees
的内容,看看是否有可以手动删除的子文件夹。
--force
适用的案例数量。
peff
)(2018 年 8 月 30 日)。
sunshineco
) 。
gitster
-- 在
commit 1c515bf 中 merge ,2018 年 9 月 17 日)
worktree
: delete.git/worktrees
if empty after 'remove
'
For cleanliness, "
git worktree prune
" deletes the.git/worktrees
directory if it is empty after pruning is complete.For consistency, make "
git worktree remove <path>
" likewise delete.git/worktrees
if it is empty after the removal.
pclouds
) 的
commit a8c754d(2018 年 10 月 21 日)。
newren
) 在
Junio C Hamano -- gitster
-- 中 merge ,2018 年 11 月 13 日)
refs
: new ref types to make per-worktree refs visible to all worktrees
One of the problems with multiple worktree is accessing per-worktree refs of one worktree from another worktree.
This was sort of solved by multiple ref store, where the code can open the ref store of another worktree and has access to the ref space of that worktree.The problem with this is reporting.
"HEAD
" in another ref space is also called "HEAD" like in the current ref space.
In order to differentiate them, all the code must somehow carry the ref storearound and print something like "HEAD from this ref store
".Instead of entering a separate ref space, we make refs from other worktrees available in the current ref space.
So "HEAD
" is always HEAD of the current worktree, but then we can have"worktrees/blah/HEAD
" to denote HEAD from a worktree named"blah
".
This syntax coincidentally matches the underlying directory structure which makes implementation a bit easier.The main worktree has to be treated specially because well... it'sspecial from the beginning.
So HEAD from the main worktree is acccessible via the name "main-worktree/HEAD
" instead of "worktrees/main/HEAD
" because "main
" could be just another secondary worktree.This patch also makes it possible to specify refs from one worktree inanother one, e.g.
git log worktrees/foo/HEAD
worktrees/<name>/HEAD
”)导致 Git 2.23(2019 年第 2 季度),其中的代码现在清理了工作树的名称,以确保这些引用格式正确。
pclouds
) 。
peff
) 在
Junio C Hamano -- gitster
-- 中 merge ,2019 年 6 月 13 日)
worktree add
: sanitize worktree names
Worktree names are based on
$(basename $GIT_WORK_TREE)
.
They aren't significant until 3a3b9d8 (refs
: new ref types to make per-worktree refs visible to all worktrees - 2018-10-21, Git v2.20.0-rc0), where worktree name could be part of a refname and must follow refname rules.Update '
worktree add
' code to remove special characters to followthese rules. In the future the user will be able to specify theworktree name by themselves if they're not happy with this dumbcharacter substitution.
git worktree add
”在连接到同一存储库的另一个工作树损坏时会失败,这已得到纠正。
pclouds
) merge 于
Junio C Hamano -- gitster
-- ,2019 年 7 月 25 日)
worktree add
: be tolerant of corrupt worktrees
find_worktree()
can die() unexpectedly because it usesreal_path()
instead of the gentler version.When it's used in 'git worktree add' (added in cb56f55 (
worktree
: disallow adding same path multiple times, 2018-08-28, Git v2.20.0-rc0), or since v2.20.0. Though the real bug infind_worktree()
is much older) and there's a bad worktree, thisdie()
could prevent people from adding new worktrees.The "bad" condition to trigger this is when a parent of the worktree'slocation is deleted. Then
real_path()
will complain.Use the other version so that bad worktrees won't affect '
worktree add
'.
The bad ones will eventually be pruned, we just have to tolerate them for a bit.
git worktree
”可能认为
add <path>
已经是注册的工作树,即使它不是,并拒绝添加新的工作树。
<path>
的
commit bb69b3b 、
commit bb4995f 、
commit a80c4c2 (2020 年 2 月 24 日)。
sunshineco
) 在
Junio C Hamano -- gitster
-- 中 merge ,2020 年 3 月 5 日)
worktree
: don't allow "add
" validation to be fooled by suffix matchingReported-by: Cameron Gunnin
Signed-off-by: Eric Sunshine
"
git worktree
add <path>
" performs various checks before approving<path>
as a valid location for the new worktree.Aside from ensuring that
<path>
does not already exist, one of the questions it asks is whether<path>
is already a registered worktree.
To perform this check, it queriesfind_worktree()
and disallows the "add
" operation iffind_worktree()
finds a match for<path>
.
As a convenience, however,find_worktree()
casts an overly wide net to allow users to identify worktrees by shorthand in order to keep typing to a minimum.
For instance, it performs suffix matching which, given subtrees "foo/bar
" and "foo/baz
", can correctly select the latter when asked only for "baz
"."
add
" validation knows the exact path it is interrogating, so this sort of heuristic-based matching is, at best, questionable for this use-case and, at worst, may may accidentally interpret<path>
as matching an existing worktree and incorrectly report it as already registered even when it isn't.
(In fact,validate_worktree_add()
already contains a special case to avoid accidentally matching against the main worktree, precisely due to this problem.)Avoid the problem of potential accidental matching against an existing worktree by instead taking advantage of
find_worktree_by_path()
which matches paths deterministically, without applying any sort of magic shorthand matching performed byfind_worktree()
.
worktree
: improvefind_worktree()
documentationSigned-off-by: Eric Sunshine
Do a better job of explaining that
find_worktree()
's main purpose is to locate a worktree based upon input from a user which may be some sort of shorthand for identifying a worktree rather than an actual path.For instance, one shorthand a user can use to identify a worktree is by unique path suffix (i.e. given worktrees at paths "
foo/bar
" and "foo/baz
", the latter can be identified simply as "baz
").
The actual heuristicsfind_worktree()
uses to select a worktree may be expanded in the future (for instance, one day it may allow worktree selection by<id>
of the.git/worktrees/<id>/
administrative directory), thus the documentation does not provide a precise description of how matching is performed, instead leaving it open-ended to allow for future enhancement.While at it, drop mention of the non-NULL requirement of
prefix
sinceNULL
has long been allowed.For instance,
prefix_filename()
has explicitly allowedNULL
since 116fb64e43 (prefix_filename
: drop length parameter, 2017-03-20, Git v2.13.0-rc0), andfind_worktree()
itself since e4da43b1f0(prefix_filename
: return newly allocated string, 2017-03-20, Git v2.13.0-rc0).
git worktree move
的
commit 810382e 、
commit d179af6 、
commit 916133e 、
commit 4a3ce47 、
commit dd9609a 、
commit 1b14d40(2020 年 6 月 10 日)和
commit c9b77f2(2020 年 6 月 8 日)。
sunshineco
) 在
Junio C Hamano -- gitster
-- 中 merge ,2020 年 6 月 22 日)
git worktree
的
commit 810382e 、
commit d179af6 、
commit 916133e 、
commit 4a3ce47 、
commit dd9609a 、
commit 1b14d40(2020 年 6 月 10 日)和
commit c9b77f2(2020 年 6 月 8 日)。
sunshineco
) 在
Junio C Hamano -- gitster
-- 中 merge ,2020 年 6 月 22 日)
worktree
: prune duplicate entries referencing same worktree pathSigned-off-by: Eric Sunshine
A fundamental restriction of linked working trees is that there must only ever be a single worktree associated with a particular path, thus "
git worktree add
" explicitly disallows creation of a new worktree at the same location as an existing registered worktree.Nevertheless, users can still "shoot themselves in the foot" by mucking with administrative files in
.git/worktree/<id>/
.Worse, "
git worktree move
" is careless and allows a worktree to be moved atop a registered but missing worktree (which can happen, for instance, if the worktree is on removable media).For instance:
$ git clone foo.git
$ cd foo
$ git worktree add ../bar
$ git worktree add ../baz
$ rm -rf ../bar
$ git worktree move ../baz ../bar
$ git worktree list
.../foo beefd00f [master]
.../bar beefd00f [bar]
.../bar beefd00f [baz]Help users recover from this form of corruption by teaching "
git worktree prune
" to detect when multiple worktrees are associated with the same path.
worktree
: prune linked worktree referencing main worktree pathReported-by: Jonathan Müller
Signed-off-by: Eric Sunshine
"
git worktree prune
" detects when multiple entries are associated with the same path and prunes the duplicates.However, it does not detect when a linked worktree points at the path of the main worktree.
Although "git worktree add
" disallows creating a new worktree with the same path as the main worktree, such a case can arise outside the control of Git even without the user mucking with.git/worktree/<id>/
administrative files.For instance:
$ git clone foo.git
$ git -C foo worktree add ../bar
$ rm -rf bar
$ mv foo bar
$ git -C bar worktree list
.../bar deadfeeb [master]
.../bar deadfeeb [bar]Help the user recover from such corruption by extending "
git worktree prune
" to also detect when a linked worktree is associated with the path of the main worktree.
worktree: teach
list
to annotate locked worktree
The "
git worktree list
" shows the absolute path to the working tree,the commit that is checked out and the name of the branch. It is notimmediately obvious which of the worktrees, if any, are locked."git worktree remove" refuses to remove a locked worktree with an error message. If "
git worktree list
" told which worktrees are locked in its output, the user would not even attempt to remove such a worktree, or would realize that"git worktree remove -f -f <path>
" is required.Teach "
git worktree list
" to append "locked
" to its output.
The output from the command becomes like so:$ git worktree list
/path/to/main abc123 [master]
/path/to/worktree 456def (detached HEAD)
/path/to/locked-worktree 123abc (detached HEAD) locked
git worktree add --lock
)学会了记录工作树被自定义消息锁定的原因。
SRManz
) merge ,2021 年 7 月 28 日)
worktree
: teachadd
to accept--reason <string>
with--lock
Signed-off-by: Stephen Manz
Reviewed-by: Eric Sunshine
The default reason stored in the lock file, "
added with --lock
", is unlikely to be what the user would have given in a separategit worktree lock
(man) command.
Allowing--reason
to be specified along with--lock
when adding a working tree gives the user control over the reason for locking without needing a second command.
gitster
现在包含在其
Junio C Hamano -- git worktree
-- 中:
git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]] [-b <new-branch>] <path> [<commit-ish>]
git worktree
现在包含在其
commit 01369fd 中:
With
lock
or withadd --lock
, an explanation why the working tree is locked.
关于Git 工作树 : two worktrees point in the same location, 无法修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35598477/
我有一个 master和一个 setup在我的 repo 中分支。我保留了 setup分支 check out 作为主 repo 文件夹内的工作树通过 git worktree add ./local
在 git 中设置分离的工作树有哪些优势和/或合适的用例?我对涉及服务器链(例如本地主机 -> 登台服务器 -> 实时服务器)的工作流的情况特别感兴趣。 最佳答案 最大的优势(至少我看到了)是能够 p
在 git 中设置分离的工作树有哪些优势和/或合适的用例?我对涉及服务器链(例如本地主机 -> 登台服务器 -> 实时服务器)的工作流的情况特别感兴趣。 最佳答案 最大的优势(至少我看到了)是能够 p
我正在使用 git version 2.14.2.windows.2 并调用 git worktree add 在“正常”存储库上创建工作树。这在 创建了一个新的工作树结构对于分支并添加了 .g
我正在研究 git 的"new"worktree 功能,因为它似乎非常适合我经常遇到的问题:需要同时在多个分支中工作(其中一些是短暂的而其他人真的很长寿)。 我通常需要在 release_a bran
我使用 git worktree add 创建了一个新的工作树。我注意到它在 repo 中创建了一个与工作树同名的新分支。这个分支是做什么用的? 我已经检查了第二个工作树中另一个预先存在的分支。我可以
我读了Github's post on git-worktree .他们写道: Suppose you're working in a Git repository on a branch calle
在我的机器上,我将 --skip-worktree 设置为 config/database.yml。 git update-index --skip-worktree config/database.
我用过git update-index --skip-worktree 按照建议here使 git 忽略对跟踪文件的本地更改。但是现在我忘记了我将它应用于哪些文件。如何列出应用了 skip-workt
我想做什么 我有一个包含敏感数据的文件,所以我不想将此文件的内容推送到远程服务器。 我做了什么? 为了实现这一点,我在文件为空时进行了提交,并将这个空文件推送到服务器 (GitHub)。然后用敏感数据
我在我正在使用的脚本中看到了这一行: git config core.worktree .. 我不确定 git worktree 做了什么,但我完全不明白为什么将它设置为 .. 任何线索? 谢谢 最佳
我有一个本地 git 存储库,我使用 git 工作树层次结构。到目前为止,我尝试过的任何应用程序都可以很好地与 git worktrees 配合使用,但是 Visual Studio 提示给定的目录不
我正在 Windows 的本地存储库中打开一个新的工作树,但无法在我的 Linux 虚拟机中编译它,因为“.git”包含以“C:/Git”开头的完整路径,虚拟机机器不识别。 我有一个 git 存储库,
当我这样做时 git worktree list ,显示如下。 /path/to/workspace c943d35 [master] /path/to/workspace ef4df56 (de
我自己使用 git 已经有一段时间了,现在正在为我们的团队建立一个 repo。我们开发了一个电子商务平台。 有一些目录和文件需要忽略,例如上传目录和特定于环境的配置文件。 虽然配置文件在 .gitig
不久前我这样做是为了忽略对 git 跟踪的文件的更改: git update-index --skip-worktree 现在我实际上想将该文件的更改提交给源代码。如何撤消 skip-worktre
我对文件进行了本地更改,但不想提交到我的存储库。它是用于在服务器上构建应用程序的配置文件,但我想使用不同的设置在本地构建。自然地,当我将“git status”作为要暂存的东西时,文件总是会出现。我想
我最近发现了 git worktree命令: The new working directory is linked to the current repository, sharing everyt
我的 projects 文件夹位于主机上的 /home/my/ 文件夹中,并安装在 /home/user/projects 中 docker 容器。在这个文件夹中有 git repo /home/us
作为 git 的新手,我想大致了解一下如何为一个 github 项目的不同分支使用多个工作目录。特别是我想要/需要在两个分支上工作——一个是“主”分支,另一个是维护版本,比如 maintenance/
我是一名优秀的程序员,十分优秀!