Git:很难获取现有的Git存储库来跟踪新的裸远程存储库

戴维·梅斯

简介:我很难让现有的本地存储库来跟踪新的裸远程存储库。

我尝试过的操作:在设置上游跟踪时,我尝试将本地回购推送到新的裸回购。Git告诉我正在进行上游跟踪,但是即使在获取了远程仓库后,我仍然看不到本地仓库日志中的分支被跟踪。

我还尝试了从本地存储库创建裸克隆,希望它的工作方式类似于克隆另一个自动设置跟踪的本地存储库,但我仍然看不到本地存储库日志中有跟踪的迹象。 。

请求:是否有人可以查看下面的背景信息,并指导我可能要出问题的地方,或者对如何获取现有存储库以跟踪新的裸机远程存储库有不正确的理解?谢谢,我已经尽力研究了。

背景我在一个小团队中担任制造工程师。我们想为团队使用中央共享的远程Git存储库来设置工作流程。我一直在尝试建立一个演示其运行方式的演示,下面的“ centralRepo.git”目录是我们的中央存储库,让其他文件夹的团队成员可以将中央远程服务器克隆到该文件夹​​。

因为我们已经有工作,但是没有中央远程仓库,所以我们将从“ davesClones”中的现有仓库开始,将其推送到中央远程仓库,然后根据需要克隆到其他团队成员文件夹,例如“ stevesClones 。”

资料夹范例

我期望跟踪是否正常工作:如果克隆常规的本地存储库,则会自动设置跟踪,并且日志会向我显示我的克隆自身的分支,以及从目录跟踪的“ origin”分支。克隆自,如下面的屏幕快照中以蓝色圆圈所示:

预期追踪结果

尝试1:推动w /-设置上游:

我尝试使用git push --set-upstream <remote> master如下所示的方法将现有的本地存储库推送到新的中央远程存储库,即使输出似乎显示已设置跟踪,但在git日志中也没有发生任何克隆常规跟踪时发生的跟踪回购,即使使用fetch之后。下面的示例显示了尝试上述步骤后,我如何在日志中缺少起点跟踪分支:

--set-upstream不起作用

尝试2:克隆-裸露:

我还尝试将现有存储库克隆到新的裸存储库,希望这会自动建立跟踪,但是如下所示,即使在获取后,日志似乎也未显示任何跟踪发生:

将daveClone克隆为裸回购尝试

提取无济于事

知道为什么我没有在日志中看到跟踪吗?(指的是克隆标准本地存储库后的运行情况,我看到了一个跟踪[来源/主设备,原始记录头,但是当使用push --set-upstream将本地存储库推送到远程时,或者使用git clone --bare能否将本地存储库克隆到裸露的远程服务器?)

此外,本地存储库中确实有提交,因此在推送或克隆到远程服务器时,它不是空的。

谢谢!

星期二

TL; DR

您需要通过在自己的Git存储库中设置一个遥控器来启动整个过程

git remote add <name> <URL-or-path>

after which you must use the name part you used, instead of typing out the (presumably longer) URL-or-path. That is, you'll do:

git remote add origin /d/Seafile/...
git push --set-upstream origin master

Long

Let me start by saying that I really dislike the word tracking here as it misleads everyone. It has done that to you, too.

We must use git remote to create or otherwise manipulate remotes. A remote is just a short name—like origin, which is kind of the standard first-name-to-use for a remote—that will store a URL (and some other more-internal-to-Git information).

I am retyping from your screenshot, so I may introduce typos, but the key is here in this line:

git push --set-upstream /d/Seafile/Development/gitTest/centralRepo.git master

Let's take a quick detour through the Git documentation. The syntax for git push is described in the SYNOPSIS lines of the documentation as (abbreviated):

git push [options] [repository [refspec...]]

Here, your lone option is --set-upstream (which on its own is fine) and your repository is given as a pathname, /d/Seafile/.... If you jump down to the OPTIONS section, the repository parameter is described all too briefly like this:

<repository>
The "remote" repository that is destination of a push operation. This parameter can be either a URL ... or the name of a remote ....

What is unfortunately omitted here is that --set-upstream, and the kind of tracking that you want, only works if the parameter given is a remote.

A path name like /d/Seafile/...—which your Git internally translated to D:/Seafile/... as you can see in other output—counts as a URL rather than a "remote".

Remotes and remote-tracking names

Rather than saying that a branch name tracks some other name, I like to use the phrase has as an upstream. This phrase is unfortunately a bit awkward (hence Git's use of track as a verb). Any branch name can have either no upstream at all, or one upstream. When a branch does have an upstream, that can be either:

  • another branch name, e.g., develop could have master as its upstream, or
  • a remote-tracking name such as origin/master.

I call names like origin/master remote-tracking names (Git documentation mostly calls these remote-tracking branch names). They come into existence by stringing together the name of a remote, such as origin, with a branch name: the name of the branch in the Git that your Git converses-with, when your Git phones up the other Git using the URL stored under that "remote".

When you use git fetch or git push, you have your Git phone up another Git. There are two Gits; each Git has its own branches. Your Git has your branches, and their Git has theirs. Your Git offers to remember their names for you, as a service ... but for your Git to remember their branch names, your Git must come up with a name for each one that does not interfere with your own branch names. Your Git does that by pasting something in front of their branch names.1

The part that gets pasted-in-front here is the remote name, e.g., origin. Without a remote—with a URL instead—there's nothing to paste-in-front, so the pasting-in-front never happens. The --set-upstream option becomes inoperative.

So why did your Git print:

Branch 'master' set up to track remote branch 'master' from 'D:/Seafile/Development/gitTest/centrapRepo.git'.

唯一可能的答案是,Git非常的Gitty。它只是说它做了一些物理上无法做的事情,因此没有做。


1从技术上讲,远程跟踪名称位于单独的命名空间中:分支名称具有以开头的全拼写名称refs/heads/,所以master的确是refs/heads/master远程跟踪名称以开头,refs/remotes/并继续包括远程名称和另一个斜杠。名称的其余部分是在该远程服务器上URL上看到的精简分支名称。因此,它们refs/heads/master成为您的信息refs/remotes/origin/master,并显示为origin/master

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从现有的 git 存储库创建新的 git 存储库,第 2 部分

无法将本地 git master 同步到现有的 git hub 远程存储库

Git:将更改从现有(类似)存储库中提取到新克隆的裸存储库中

无法推送现有的本地git存储库

将现有的Git存储库推送到SVN

将多个现有的 git 存储库移动到一个新的父存储库中

如何将新代码推送到 github 中现有的 git 存储库

将现有的生产文件添加到新的 Git 存储库

无法将现有的git存储库推送到新的TFS

克隆裸git存储库并跟踪其他位置的文件

用git重命名远程(裸)存储库

现有的git(专用远程)存储库已经存在。无法与以前的开发人员联系

如何将现有git存储库的副本复制到新存储库

如何在Git存储库中移动现有的Git子模块?

git裸存储库有什么用?

如何从本地还原Git裸存储库

清理大的裸git存储库失败

git中的裸共享存储库的概念

从Git的裸存储库中删除文件

git如何跟踪远程存储库中的版本?

将我的本地存储库与现有的远程存储库绑定

如何将新的本地分支推送到远程Git存储库并进行跟踪?

对充当 git 存储库的 git clone 的更改未被视为包含原始存储库中没有的新更改

如何在另一台主机上 git clone 裸远程 git 存储库

我可以在现有的TFS团队项目中创建git存储库吗?

将本地项目链接到现有的git存储库

迁移/复制现有的本地Git存储库。到TFS(Visual Studio)

将新文件推送到现有的git存储库

如何将现有的git存储库移动到新项目的外部目录