我对Git很新,所以面对一些正确使用的问题.这是我的情景.
我有一个我的主存储库的分支,并将其克隆到我的本地.在那里,我有2个分支用于不同的修复.
当我提交时,我在git中看到了一个声明 - 我们说我提前3次提交,大约20次提交.
我知道我的fork与master不同步.另外我也需要合并两个分支(或者我应该这样做?)
我使用Windows客户端进行同步.但似乎我没有遵循Git的方式.所以,我尝试按照https://help.github.com/articles/syncing-a-fork/中描述的步骤进行操作,这给出了如下错误(我正在使用Windows).
$>git fetch upstream
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我有点困惑.请帮助我在这个场景中应该遵循的步骤.
@HuStmpHrrr
很抱歉在评论中添加详细信息我会修改问题以便于阅读
通过执行命令:
$>git remote returning two values
acme-development (which the name of my actual/main repository, from where I forked) and
origin
Run Code Online (Sandbox Code Playgroud)
添加更多信息.
在获取之后,我尝试将origin/master合并到我的主人身上请查看截图
但是,如果我登录我的Github在线帐户,它会说一个不同的故事.
我的git客户端说本地仓库是最新的.但在线git表示,我们有42个提交,7个提交.
Rat*_*tle 50
您链接的文章(尽管自您提出以来可能已更改)以对https://help.github.com/articles/configuring-a-remote-for-a-fork/的引用开头.如果您完成此操作,您将拥有一个名为upstream的新远程存储库,指向您分叉的原始存储库,并且git fetch upstream
可以正常运行.
所以有一些事情需要澄清:
Upstream是存在的远程存储库(或存储库)的概念名称.大多数项目只有一个上游存储库.
上游存储库的名称可能因项目而异,但按照惯例是起源.
也就是说,我愿意打赌你得到了你的上游回购的名称和上游回购概念的混淆,你应该执行git fetch origin
.验证git remote
; 使用该列表中的相应名称.
但是,如果您只有一个上游回购,那么执行git fetch
将完成同样的事情.
以下步骤将使您能够链接您的 git fork 和原始存储库,以便您可以在原始存储库更新时随时从原始存储库中提取更改。转到 github 上的存储库页面并单击 fork(如果您还没有这样做)。假设您从https://github.com/account/repo-name分叉了一个名为repo-name 的 repo,那么您会在自己的帐户上获得一份 repo 的副本(分叉),例如https://github.com/your -user-name/repo-name然后在终端上运行以下命令
git clone https://github.com/your-user-name/repo-name.git
Run Code Online (Sandbox Code Playgroud)
cd repo-name
Run Code Online (Sandbox Code Playgroud)
git remote add upstream https://github.com/account/repo-name.git
Run Code Online (Sandbox Code Playgroud)
git pull upstream master
Run Code Online (Sandbox Code Playgroud)
git branch --set-up-stream-to=upstream/master
Run Code Online (Sandbox Code Playgroud)
git pull
Run Code Online (Sandbox Code Playgroud)
当您进行更改并希望将其集成到原始代码库中时,为了将您的更改添加到原始存储库中,您必须首先在 github 上推送到您的分支并发送拉取请求,然后该请求将被验证并合并到代码库中。下面的步骤。
git add .
Run Code Online (Sandbox Code Playgroud)
git commit -m "commit message"
Run Code Online (Sandbox Code Playgroud)
git push origin master
Run Code Online (Sandbox Code Playgroud)
然后访问您在 github 上的帐户并单击您的repo-name。在页面上,您将看到创建拉取请求的链接。单击链接并创建拉取请求,然后维护者将对其进行审查和合并。
小智 6
只需在终端上运行以下命令
$ git remote add upstream {your upstream repository link here}
Run Code Online (Sandbox Code Playgroud)
运行此命令后:
git remote -v
Run Code Online (Sandbox Code Playgroud)
此命令将显示您的 github 存储库路径和上游存储库路径。
示例输出:
origin https://github.com/ {Your Github username} / {repository name} (fetch)
origin https://github.com/ {Your Github username} / {repository name} (push)
upstream https://github.com/ {Upstream github username} / {repository name} (fetch)
upstream https://github.com/ {Upstream github username} / {repository name} (push)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23357 次 |
最近记录: |