繁体   English   中英

如何在 VS Code 中使用远程跟踪创建本地 git 分支

[英]How to create local git branch with remote tracking in VS Code

从私有 git 服务器拉取时,每当我在 VS Code 中创建分支时,它都不会跟踪上游分支。 git 输出显示它正在运行

git checkout -q -b NewBranchLocal --no-track origin/NewBranch

如果我使用 ">Git: Checkout to..." 或 ">Git: Create branch from..." 命令。

从 git 服务器中提取这些是否有最佳实践? 如何使用 VS Code 中的 git 扩展来创建原始分支的本地版本并将其绑定到该上游分支?

从我在 VS Code 的源代码中看到的,看起来 --no-track 应该只在您创建的分支被检出时才显示,但我没有看到您可以创建的选项一个分支,而不是检查出来。 查看 vscode-master/extensions/git/src 文件夹,git.ts(第 1238 行)说

    async branch(name: string, checkout: boolean, ref?: string): Promise<void> {
        const args = checkout ? ['checkout', '-q', '-b', name, '--no-track'] : ['branch', '-q', name];

        if (ref) {
            args.push(ref);
        }

        await this.run(args);
    }

唯一的参考是在repository.ts(第979行):

    async branch(name: string, _checkout: boolean, _ref?: string): Promise<void> {
        await this.run(Operation.Branch, () => this.repository.branch(name, _checkout, _ref));
    }

这在 commands.ts 文件中调用(第 1563 行)

    private async _branch(repository: Repository, defaultName?: string, from = false): Promise<void> {
        const branchName = await this.promptForBranchName(defaultName);

        if (!branchName) {
            return;
        }

        let target = 'HEAD';

        if (from) {
            const picks = [new HEADItem(repository), ...createCheckoutItems(repository)];
            const placeHolder = localize('select a ref to create a new branch from', 'Select a ref to create the \'{0}\' branch from', branchName);
            const choice = await window.showQuickPick(picks, { placeHolder });

            if (!choice) {
                return;
            }

            target = choice.label;
        }

        await repository.branch(branchName, true, target);
    }

所以没有能力不检查那个分支,也没有机会将新的本地分支链接到源。

我在 vscode-master 项目中找不到任何其他参考资料,所以我不知道下一步该往哪里看。

根据这个 VS Code 问题,Git: Checkout to... 命令将显示一个分支列表。 如果您选择远程分支,它将创建一个本地分支并将其设置为跟踪远程分支。 我刚刚使用 VS Code 1.47.3 对此进行了测试,它创建了具有跟踪功能的本地分支。 也许他们在您在这里发布问题后解决了这个问题?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM