繁体   English   中英

使用git pull和git push命令在origin master和origin / master之间进行区分

[英]Difference between origin master & origin/master with git pull and git push commands

我是git的新手我对git pull和git push命令几乎没有疑问。

例:
让我们假设我在本地机器“master”和“newbranch”(本地分支)中有两个分支。

$ git checkout newbranch

$ git branch

  *newbranch           //Assume this is local branch only 
    master

现在,以下命令到底是做什么的?

git pull origin master - >它会将更改从远程“master”拉到“newbranch”(当前结帐本地分支)。

git pull origin / master - >它会将'local'“master”中的最新更改拉到“newbranch”(当前结帐本地分支)。

git push origin master - >它会将“newbranch”(当前结帐本地分支)中的新更改推送到“remote”“master”。

git push origin / master - > ?? 这究竟是做什么的?

任何人都可以澄清疑问。

                                                         Thanks in advance 

git pull origin mastergit pull origin/master

它会将更改从远程master服务器提取到“newbranch”(当前结帐本地分支)。

确切地说 - 两者都会做同样的事情
最小的区别是origin/master将引用存储在存储库中的本地副本。

最佳实践是在使用以下方法更新本地存储库之前:

git fetch --all --prune

git push origin master

将“newbranch”(目前结帐本地分支)的新变化推送到“远程”“主”。

那种
Git会尝试将当前分支推送到远程主服务器,因为你在不同的分支上然后掌握(取决于你本地的git版本)git不会让你这样做。

如果分支存在于远程中,它将尝试推送到相同的分支名称(被跟踪的分支),并再次依赖于它将推送到远程的git版本或将引发错误。

在此输入图像描述


git push origin/master

它将推送到远程跟踪分支。
Git将使用origin/master作为远程名称,并尝试将当前分支名称推送到此远程。

在你的情况下,如果你在newbranch它将尝试推送到远程命名origin/master ab分支名称newbranch

在此输入图像描述

通常,此命令的语法是:

git push <remote> [refspec]

如果省略refspec,则简化为:

git push <remote>

它的行为取决于git config push.default变量中设置的内容。 git消息说:

当push.default设置为'matching'时,git会将本地分支推送到已存在的具有相同名称的远程分支。

在Git 2.0中,Git将默认为更保守的“简单”行为,它只将当前分支推送到'git pull'用于更新当前分支的相应远程分支。

要设置“匹配”模式:

git config --global push.default matching

并设置'简单'模式:

git config --global push.default simple

让我们回到你的具体案例。 将提交提交到名为“origin / master”的远程控制器将失败,因为没有“origin / master”远程存在(默认远程称为“origin”)。 要使其工作,您必须手动添加此类远程,例如通过调用:

git remote add origin/master <git-repository-url>

但是请注意,这样的操作会让你的本地git非常困惑,你将不得不处理这样的错误:

$ git push origin/master
Counting objects: 5, done.
Writing objects: 100% (3/3), 253 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:sarxos/test.git
   820474f..3706ea9  master -> master
error: unable to resolve reference refs/remotes/origin/master/master: Not a directory
error: Cannot lock the ref 'refs/remotes/origin/master/master'.

还有一些:

$ git fetch origin/master
error: unable to resolve reference refs/remotes/origin/master/master: Not a directory
From github.com:sarxos/test
 ! [new branch]      master     -> origin/master/master  (unable to update local ref)
error: some local refs could not be updated; try running
 'git remote prune origin/master' to remove any old, conflicting branches

所以我不建议使用它。

如果你想推送到origin / master(名为'origin'的远程名称和名为'master'的远程分支),你应该:

git push origin master

暂无
暂无

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

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