git tracking不适用于不同的本地和远程名称?

时间:2010-11-08 04:48:40

标签: git

如果我这样做

git checkout -b samename origin/samename

然后跟踪似乎工作正常。如果我做后续提交,我可以做

git push

并且git将我的提交推迟到原点。

然而,如果我这样做

git checkout -b diffname origin/samename

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

$ 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只是给'一切都是最新的' 是什么给了什么?

我在mac os x上运行git 1.7.1

以下是那些想在家尝试的人的整个实验:

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

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

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

1 个答案:

答案 0 :(得分:4)

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

  

push.default

     

定义如果在命令行上没有给出refspec,在远程中没有配置refspec,并且命令行上给出的任何选项都没有暗示refspec,那么git push应采取的操作。可能的值有:

     
      
  • 什么都没有 - 不要推任何东西。
  •   
  • 匹配 - 推送所有匹配的分支。两端具有相同名称的所有分支都被认为是匹配的。这是默认设置。
  •   
  • 跟踪 - 将当前分支推送到其上游分支。
  •   
  • current - 将当前分支推送到同名分支。
  •   

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

至于你对Pro Git的引用......哇,Pro Git通常是一个很好的资源。我一直没有读过它(我倾向于直接阅读联机帮助页和源代码),但我读到的一切都很棒;我很惊讶地看到一个小小的错误!