Git Extensions + Git For Windows:获取本地不存在的分支不会创建新的本地分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11129913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:06:28  来源:igfitidea点击:

Git Extensions + Git For Windows: Fetching Branch that does not exist Locally does not Create New Local Branch

gitgit-extensions

提问by Simon Tewsi

I'm running Git Extensions 2.32 on Git For Windows (previously known as msysgit) 1.7.10.msysgit.1.

我在 Git For Windows(以前称为 msysgit)1.7.10.msysgit.1 上运行 Git 扩展 2.32。

Another user has created a new branch and pushed it to the remote repository. I want to fetch that new branch down to my local repository.

另一个用户创建了一个新分支并将其推送到远程存储库。我想将该新分支提取到我的本地存储库。

This imageshows what I'm trying to do. The master is currently checked out and the other user has added a new branch, "brentfo", which he has pushed up the remote repository. I want to now fetch that new branch down to my local repository.

这张图片显示了我正在尝试做的事情。master 当前已被检出,另一个用户添加了一个新分支“brentfo”,他已将其推送到远程存储库。我现在想将该新分支提取到我的本地存储库。

I open the Git Extensions Pull dialog, as seen in the image. I'm pulling from the origin with merge option "Do not merge, only fetch remote changes", selecting the new Remote branch "brentfo". When I click on the Pull button I get a progress dialog:

我打开 Git Extensions Pull 对话框,如图所示。我正在使用合并选项“不合并,只获取远程更改”从源中提取,选择新的远程分支“brentfo”。当我点击 Pull 按钮时,我会看到一个进度对话框:

c:\Program Files (x86)\Git\bin\git.exe fetch --progress "origin" +refs/heads/brentfo
Done
From //dnzchfile1/git-chch$/mRouteDotNET
 * branch            brentfo    -> FETCH_HEAD

The progress dialog does not show any error. It appears the process completes normally.

进度对话框没有显示任何错误。看起来该过程正常完成。

The FETCH_HEAD file shows the following:

FETCH_HEAD 文件显示以下内容:

eea033921fea43acf34a5baa380d1666181b56aa        branch 'master' of //server/gitrepo/mRouteDotNET
5e0640e42d04a744aae2e95663a13c0747cacaf1    not-for-merge   branch 'brentfo' of //server/gitrepo/mRouteDotNET
934e6034c526b703ac69b26497e0131f9bb71c2c    not-for-merge   branch 'mRoutePCLib' of //server/gitrepo/mRouteDotNET

When I look at the commit log afterwards, however, nothing seems to have happened (the commit log appears in the background in the image of the Pull dialog, above). The new branch, brentfo, has not been created in my local repository. When I pull down the dropdown list of branches there are still only two: master and mRoutePCLib.

然而,当我之后查看提交日志时,似乎什么也没发生(提交日志出现在上方拉对话框图像的背景中)。新分支 brentfo 尚未在我的本地存储库中创建。当我下拉分支的下拉列表时,仍然只有两个:master 和 mRoutePCLib。

I get the same result if, in the Pull dialog, I don't select any Remote branch (ie leave it blank). In that case the progress dialog shows:

如果在 Pull 对话框中没有选择任何远程分支(即留空),我会得到相同的结果。在这种情况下,进度对话框显示:

c:\Program Files (x86)\Git\bin\git.exe fetch --progress "origin" 
Done

There appears to have once been a bug to do with creating local branches from remote ones in earlier versions of Git Extensions. However, looking at the Git Extensions project change logthe problem looks like it was solved way back in version 1.55. So I'm guessing I'm doing something wrong.

在早期版本的 Git 扩展中,从远程分支创建本地分支似乎曾经存在一个错误。但是,查看 Git Extensions 项目更改日志,问题似乎已在 1.55 版中得到解决。所以我猜我做错了什么。

I know I can use the Git Bash console to fetch the remote branch and create a new local one from it. However, it seems to be I should be able to do this via the GUI.

我知道我可以使用 Git Bash 控制台来获取远程分支并从中创建一个新的本地分支。但是,似乎我应该能够通过 GUI 来做到这一点。

I'm hoping for answers along the lines of either:

我希望得到以下任一方面的答案:

a) Yes, you're doing it wrong and here's how you should do it (via the GUI); or

a) 是的,你做错了,这里是你应该怎么做(通过 GUI);或者

b) This is a known issue, you'll have to do it from the command-line interface (Git Bash) until the bug is fixed.

b) 这是一个已知问题,您必须从命令行界面 (Git Bash) 执行此操作,直到修复错误为止。

Cheers Simon

干杯西蒙

回答by Andrew T Finnell

Fetching will just bring in all the changes in the current branch (and locally tracked branches? someone help me on this one.) and the knowledgeof all the remote branches. You really don't want fetch to bring down all the commits for all the branches that you haven't checked out yet.. That would be bad if there were thousands of branches. For checking out remote branches that you can't see yet, you Fetch then Checkout Branch.

获取只会带来当前分支中的所有更改(以及本地跟踪的分支?有人帮我解决这个问题。)以及所有远程分支的知识。您真的不希望 fetch 取消所有尚未签出的分支的所有提交。如果有数千个分支,那将是糟糕的。要签出您还看不到的远程分支,请先获取,然后再签出分支。

You already fetched the existence of the remote branch.

您已经获取了远程分支的存在。

Now you want to do

现在你想做

Git Extensions -> Checkout Branch

Git 扩展 -> Checkout 分支

Change it from Local to Remote. Pick the remote branch in the drop down. Say ok, it will ask if you want to create a local branch then track it. Make sure to click Yes.

将其从本地更改为远程。在下拉列表中选择远程分支。说好的,它会询问您是否要创建本地分支然后跟踪它。确保单击是。

I recommend finding some way to buy Smart Git 3. It is by far better than all the other Windows Git products. They have a free Open Source license version.

我建议寻找某种方式购买 Smart Git 3。它比所有其他 Windows Git 产品都要好得多。他们有一个免费的开源许可证版本。

回答by Simon Tewsi

Further to Andrew Finnell's answer:

进一步安德鲁芬内尔的回答:

After selecting Git Extensions > Checkout branch(from Windows Explorer context menu), the Checkout Branch dialogwill open.

选择Git 扩展 > 签出分支(从 Windows 资源管理器上下文菜单)后,签出分支对话框将打开。

Select Remote branchand the name of the remote branch to pull down and click Checkout. The Checkout Remote Branch dialogwill open.

选择Remote branch和要下拉的远程分支的名称,然后单击Checkout。在结帐远程分支对话框将打开。

In the Checkout Remote Branch dialog, select Reset local branch with the name '{branch name}'and make sure Mergeis checked, then click Checkout:

在 Checkout Remote Branch 对话框中,选择Reset local branch with name '{branch name}'并确保选中Merge,然后单击Checkout

Checkout Remote Branch dialog

签出远程分支对话框

This will create a new local branch, update it with the changes from the remote branch, and create a mapping between the local branch and the remote branch so that changes can be pushed and pulled between them.

这将创建一个新的本地分支,使用来自远程分支的更改更新它,并在本地分支和远程分支之间创建映射,以便可以在它们之间推送和拉取更改。

NOTE:Don't select "Create local branch with the name '{remote name}_{branch name}'". This will create a local branch but it will be prefixed with the name of the remote repository (in the example above the local branch would be named "origin_DSIChanges" instead of "DSIChanges").

注意:不要选择“创建名为‘{远程名称}_{分支名称}’的本地分支”。这将创建一个本地分支,但它将以远程存储库的名称作为前缀(在上面的示例中,本地分支将命名为“origin_DSIChanges”而不是“DSIChanges”)。

回答by Prakhar Jain

Yes, you're doing it wrong and here's how you should do it (via the GUI); You are fetching Remote branch commits to your local branch but You need to merge remote branch with Local branch also. Please select "Merge remote branch into current branch" option never select "Only fetch Do not merge".

是的,你做错了,这里是你应该怎么做(通过 GUI);您正在将远程分支提交获取到本地分支,但您还需要将远程分支与本地分支合并。请选择“将远程分支合并到当前分支”选项,切勿选择“仅提取不合并”。