4

我从我们的 repo 中检查了一个新分支。我们的开发分支一切正常。但是在新的分支上,'push' 并没有做任何事情。

一切看起来都很正常 - 有 2 个提交要推送。

-> git branch -vv
  develop   8ab7ef1 [origin/develop] Merge branch 'develop' of git.example.com:core-platform into develop
* hotfix112 8521cef [origin/hotfix/1.1.2: ahead 2] CORE-1263 - Completed merging from dev into hot fix.

但是 Push 什么也没做:

-> git push
Everything up-to-date

-> git status
# On branch hotfix112
# Your branch is ahead of 'origin/hotfix/1.1.2' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

我发现 'git pull' 使用远程,但 'git push' 没有:

-> git remote show origin
* remote origin
  Fetch URL: git@git.example.com:core-platform.git
  Push  URL: git@git.example.com:core-platform.git
  HEAD branch: develop
  Remote branches:
    core-platform-1.0.0 tracked
    develop             tracked
    hotfix/1.1.2        tracked
    master              tracked
    release/1.0.0       tracked
    release/1.1.1       tracked
  Local branches configured for 'git pull':
    develop   merges with remote develop
    hotfix112 merges with remote hotfix/1.1.2
  Local ref configured for 'git push':
    develop pushes to develop (up to date)
->

我不知道为什么 hotfix112 没有链接到遥控器,但 pull 是。

如何修复此配置?

4

3 回答 3

2

Git 的行为正如您所描述的,因为您有以下情况:

  • 您有一个本地分支 (hotfix112),它正在跟踪一个不同名称的远程分支
  • 您将 push.default 选项设置为匹配(默认)或简单

与 git 的通常情况一样,您有几种选择来设置 git 以根据需要执行操作:

1.) 最简单的方法是更改​​本地分支的名称以匹配远程分支的名称。之后,推送开始自动工作。所以只需将分支“hotfix112”重命名为“hotfix/1.1.2”:

git branch -m hotfix112 hotfix/1.1.2

2.) 您可以通过将选项 push.default 设置为“跟踪”来更改推送行为。因为您已经将分支 'hotfix112' 设置为跟踪 origin/hotfix/1.1.2,所以 git push 将按需要工作。要设置本地 git 选项运行:

git config --local push.default tracking

3.) 您可以手动编辑您的 .git/config 文件并设置推送以匹配本地 refspec 'hotfix112' 到远程 'hotfix/1.1.2'。您应该在 [remote "origin"] 部分下方添加推送行:

[remote "origin"]                                                               
  url = ...
  fetch = ...
  push = hotfix112:hotfix/1.1.2

第一种和第三种方法仅适用于 hotfix112 分支。第二个适用于该存储库中的所有跟踪分支(如果使用全局选项,则为全局)。

于 2013-08-13T18:22:56.370 回答
0

尝试 git push origin/hotfix/1.1.2 (远程分支) hotfix112 (本地分支),可能在推送到远程之后它会创建一个链接。奇怪的是,当你分支时并没有这样做。

于 2013-08-13T17:19:08.687 回答
0

(没有任何附加参数)的当前行为git push是在本地和远程存储库中推送所有具有相同名称的分支。由于您的本地分支名称与远程分支名称不同,如果您将它们更改为匹配,git push则应该推送您的更改。请注意,这种行为将在 git 的未来版本(可能是 2.0)中发生变化。参见:http ://article.gmane.org/gmane.comp.version-control.git/193308 。如果您想立即更改行为git push,请键入git help config并搜索“push.default”。

于 2013-08-13T18:17:15.250 回答