git跟踪不适用于不同的本地和远程名称? [英] git tracking doesn't work with different local and remote names?

查看:141
本文介绍了git跟踪不适用于不同的本地和远程名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做

$ $ p $ g $ git checkout -b同名名称/同名

然后跟踪显示工作正常。如果我做了后续的提交,那么我可以这样做:

  git push 

和git推高了我的提交原点。



但是,如果我这样做的话

  git checkout -b diffname origin / samename 

然后跟踪不起作用,尽管亲git书的这一部分:

  $ git checkout  - b sf origin / serverfix 
分支sf设置为跟踪远程分支refs / remotes / origin / serverfix。
转换到一个新的分支sf
现在,你的本地分支sf将自动地从原始/ serverfix

Git push只是给'所有最新的'
给了什么?



我正在运行git 1.7.1在Mac OS上x



以下是想要在家中尝试的实验:

  szbwood-mbp15:proj4_local bwood $ vi file1 
szbwood-mbp15:proj4_local bwood $ git add file1
szbwood-mbp15:proj4_local bwood $ git commit -mCreated file 1
[master(root-commit)5d50289]创建文件1
1个文件已更改,1个插入(+),0个删除( - )
创建模式100644 file1
szbwood-mbp15 :proj4_local bwood $ git push origin master:samename
计数对象:3,完成。
写入对象:100%(3/3),225字节,完成。
合计3(delta 0),重用0(delta 0)
开箱对象:100%(3/3),完成。
到/Users/bwood/work/gitplay/proj4_remote.git
* [新分支] master - >同名
szbwood-mbp15:proj4_local bwood $ git checkout -b同名起源/同名
设置分支同名,以便从原点跟踪远程分支同名。
转换为新分支'samename'
szbwood-mbp15:proj4_local bwood $ vi file1
szbwood-mbp15:proj4_local bwood $ git commit -a
[同名a7af908] ..
1个文件已更改,1个插入(+),0个删除( - )
szbwood-mbp15:proj4_local bwood $ git push
计数对象:5,完成。
写入对象:100%(3/3),251字节,完成。
合计3(delta 0),重用0(delta 0)
开箱对象:100%(3/3),完成。
至/Users/bwood/work/gitplay/proj4_remote.git
5d50289..a7af908同名 - >同名
szbwood-mbp15:proj4_local bwood $ git checkout -b diffname origin / samename
设置分支diffname以跟踪来自原点的远程分支同名。
转换为新分支'diffname'
szbwood-mbp15:proj4_local bwood $ vi file1
szbwood-mbp15:proj4_local bwood $ git commit -a
[diffname c5bbec1] ..
1个文件已更改,1个插入(+),0个删除( - )
szbwood-mbp15:proj4_local bwood $ git push
所有最新的


$ b

奇怪的是,配置文件看起来很好..

  [branchsamename] 
remote = origin
merge = refs / heads / samename
[branchdiffname]
remote = origin
merge = refs / heads / samename


解决方案

关于跟踪。默认情况下, git push 根本不使用跟踪。它将具有匹配名称的分支推送到指定的远程。有一个配置参数来控制这种行为:


push.default



定义如果在命令行上没有给出refspec,则在远程中没有配置refspec,并且在命令行上给出的任何选项都没有暗示refspec。可能的值包括:


  • nothing - 不推送任何内容。
  • 匹配 - 推送所有匹配的分支。所有在两端具有相同名称的分支都被认为是匹配的。这是默认值。

  • tracking - 将当前分支推送到其上游分支。

  • 当前分支 - 将当前分支推送到相同分支名称。

同样,默认值是匹配的,所以尽管您的追踪设置在您的第一种情况,它只是匹配的名称,告诉它要推送什么。如果你愿意,你当然可以设置 push.default 跟踪,并获得你期待的行为。 / p>

至于Pro Git的报价...哇,Pro Git通常是一个很好的资源。我还没有完整阅读(我倾向于直接阅读manpages和源代码),但是我读过的所有内容都很棒;我很惊讶地发现一个小小的错误!

If I do

git checkout -b samename origin/samename

then tracking appears to work fine. If I do subsequent commits, I can then do

git push

and git pushed up my commits to origin fine.

However, if I do

git checkout -b diffname origin/samename

then tracking doesn't work, despite this section of the pro git book:

$ git checkout -b sf origin/serverfix
Branch sf set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "sf"
Now, your local branch sf will automatically push to and pull from origin/serverfix

Git push just gives 'Everything up to date' What gives?

I am running git 1.7.1 on mac os x

Here's the whole experiment for those that want to try it at home:

szbwood-mbp15:proj4_local bwood$ vi file1
szbwood-mbp15:proj4_local bwood$ git add file1
szbwood-mbp15:proj4_local bwood$ git commit -m"Created file 1"
[master (root-commit) 5d50289] Created file 1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file1
szbwood-mbp15:proj4_local bwood$ git push origin master:samename
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /Users/bwood/work/gitplay/proj4_remote.git
 * [new branch]      master -> samename
szbwood-mbp15:proj4_local bwood$ git checkout -b samename origin/samename
Branch samename set up to track remote branch samename from origin.
Switched to a new branch 'samename'
szbwood-mbp15:proj4_local bwood$ vi file1
szbwood-mbp15:proj4_local bwood$ git commit -a
[samename a7af908] ..
 1 files changed, 1 insertions(+), 0 deletions(-)
szbwood-mbp15:proj4_local bwood$ git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 251 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /Users/bwood/work/gitplay/proj4_remote.git
   5d50289..a7af908  samename -> samename
szbwood-mbp15:proj4_local bwood$ git checkout -b diffname origin/samename
Branch diffname set up to track remote branch samename from origin.
Switched to a new branch 'diffname'
szbwood-mbp15:proj4_local bwood$ vi file1
szbwood-mbp15:proj4_local bwood$ git commit -a
[diffname c5bbec1] ..
 1 files changed, 1 insertions(+), 0 deletions(-)
szbwood-mbp15:proj4_local bwood$ git push
Everything up-to-date

The weird thing is, the config file looks fine..

[branch "samename"]
        remote = origin
        merge = refs/heads/samename
[branch "diffname"]
        remote = origin
        merge = refs/heads/samename

解决方案

This isn't about tracking. git push by default doesn't use tracking at all. It pushes branches with matching names to the specified remote. There's a config parameter to control this behavior:

push.default

Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

  • nothing - do not push anything.
  • matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
  • tracking - push the current branch to its upstream branch.
  • current - push the current branch to a branch of the same name.

Again, the default is matching, so although you do have tracking set up in your first case, it's just the matching names that tell it what to push. If you want, you can certainly set push.default to tracking, and get the behavior you're expecting.

As for your quote from Pro Git... wow, Pro Git is generally a great resource. I haven't read it all the way through (I tend to head straight for manpages and source code), but everything I've read is great; I'm surprised to see even a tiny mistake!

这篇关于git跟踪不适用于不同的本地和远程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆