远程 git 工作树已分离
Remote git worktree is detached
我正在尝试将工作树添加到远程分支,如果该分支未存储在本地。
我可以成功执行此操作并使用以下命令获取所有文件:
git worktree add issue origin/issue
产生以下输出:
Preparing issue (identifier issue)
HEAD is now at d4bb4b9 Action edit performed on issue: ISSUE-1
这使得工作树看起来好像成功了。如果我查看文件,一切都在那里。
然而,git status 命令看起来像这样
git status
Not currently on any branch.
nothing to commit, working tree clean
而且我push/pull什么也做不了。 Git 版本是 2.14.1 btw windows(如果它有所不同)
有谁知道如何解决这个问题?如果分支是本地的并且你删除了 origin/,它工作得很好。只是在处理它似乎不太同意的遥控器。
git worktree add [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]
所以尝试:
git worktree add --checkout -b issue ../a/path origin/issue
OP Liam Kelly adds :
However you don't actually need the --checkout
for the command, using -b
is all you need.
I didn't even think about -b
being able to create the branch locally from a remote.
If the branch is local and you remove the origin/, it works perfectly fine. It's just dealing with the remote that it seems to not agree with.
您不能在远程分支上工作(在工作树或普通存储库中)。您可以只在本地分支机构上工作(推拉)。
因此您必须创建您将在工作树中使用的本地跟踪分支。
当您推送时,远程分支由 git 和 fetch/pull 更新,以在命令为 运行 时镜像远程存储库中分支的状态。
所以你可以:
- 在现有本地分支(当前分支除外)上创建工作树
- 在创建工作树的同一 time/command 中创建一个分支,以便能够在其中提交。
我正在尝试将工作树添加到远程分支,如果该分支未存储在本地。
我可以成功执行此操作并使用以下命令获取所有文件:
git worktree add issue origin/issue
产生以下输出:
Preparing issue (identifier issue)
HEAD is now at d4bb4b9 Action edit performed on issue: ISSUE-1
这使得工作树看起来好像成功了。如果我查看文件,一切都在那里。
然而,git status 命令看起来像这样
git status
Not currently on any branch.
nothing to commit, working tree clean
而且我push/pull什么也做不了。 Git 版本是 2.14.1 btw windows(如果它有所不同)
有谁知道如何解决这个问题?如果分支是本地的并且你删除了 origin/,它工作得很好。只是在处理它似乎不太同意的遥控器。
git worktree add [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]
所以尝试:
git worktree add --checkout -b issue ../a/path origin/issue
OP Liam Kelly adds
However you don't actually need the
--checkout
for the command, using-b
is all you need.
I didn't even think about-b
being able to create the branch locally from a remote.
If the branch is local and you remove the origin/, it works perfectly fine. It's just dealing with the remote that it seems to not agree with.
您不能在远程分支上工作(在工作树或普通存储库中)。您可以只在本地分支机构上工作(推拉)。
因此您必须创建您将在工作树中使用的本地跟踪分支。
当您推送时,远程分支由 git 和 fetch/pull 更新,以在命令为 运行 时镜像远程存储库中分支的状态。
所以你可以:
- 在现有本地分支(当前分支除外)上创建工作树
- 在创建工作树的同一 time/command 中创建一个分支,以便能够在其中提交。