Git 头脑混乱?

Git heads messed up?

在分支dev下,当我运行

git status

我明白了

On branch dev
Your branch is up-to-date with 'hub/dev'.

nothing to commit, working directory clean

当我运行

git remote show hub

我明白了

* remote hub   
  Fetch URL: ssh://user@user.com/home/user/private/repos/user_hub.git
  Push  URL: ssh://user@user.com/home/user/private/repos/user_hub.git   

  HEAD branch: master   
  Remote branches:
            dev        tracked
            master     tracked
            userModule tracked
  Local branches configured for 'git pull':
            dev    merges with remote dev
            master merges with remote master
  Local refs configured for 'git push':
            dev        pushes to dev        (up to date)
            master     pushes to master     (up to date)
            userModule pushes to userModule (up to date)

没想到会得到HEAD branch: master。怎么了?

问题/疑问

dev下,当我运行git push时,它推到hub/master,而应该推到hub/dev。我该如何解决这个问题,以便当我们在分支 dev 上时,它会推送到 hub/dev

更新

根据一些评论,上面的配置似乎是正确的。

请参阅下面我的 post-update 挂钩;问题可能是由它引起的吗?

#!/bin/sh

echo
echo "**** Pulling changes... [Hub's post-update hook]"
echo

case "  " in
*'refs/heads/dev'*)
cd /home/user/www/dev/ || exit
        unset GIT_DIR
        git pull hub dev
        echo
        echo "Dev was pulled"
        echo
        ;;
esac

case "  " in
*'refs/heads/master'*)
        cd /home/user/www/www/ || exit
        unset GIT_DIR
        git fetch hub && git reset --hard hub/master
        echo
        echo "Master was reset to reflect bare changes. PRAY THE LORD!"
        echo
        ;;
esac

exec git-update-server-info

这是 git 配置:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "hub"]
        url = ssh://user@user.com/home/user/private/repos/user_hub.git
        fetch = +refs/heads/*:refs/remotes/hub/*
[branch "master"]
        remote = hub
        merge = refs/heads/master
[branch "dev"]
        remote = hub
        merge = refs/heads/dev
[merge]
        renameLimit = 999999

更新二: 问题似乎已解决,但据我所知,我没有对 "fix" 采取任何措施。 :s 尽管如此,如果有人想澄清是否有问题,或者为什么这可能是个问题,请告诉我。非常感谢你。

您使用的 git 是什么版本?
在 git v2.0 之前 git push 将推送 所有 您的分支,而不提供 origin/branch 名称!!!

阅读发行说明的第一段: https://git.kernel.org/cgit/git/git.git/tree/Documentation/RelNotes/2.0.0.txt

When "git push [$there]" does not say what to push, we have used the traditional "matching" semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there). In Git 2.0, the default is now the "simple" semantics, which pushes:

  • only the current branch to the branch with the same name, and only when the current branch is set to integrate with that remote branch, if you are pushing to the same remote as you fetch from; or

  • only the current branch to the branch with the same name, if you are pushing to a remote that is not where you usually fetch from.

You can use the configuration variable "push.default" to change this. If you are an old-timer who wants to keep using the "matching" semantics, you can set the variable to "matching", for example. Read the documentation for other possibilities.

正如您在问题中所描述的那样 - 您的开发状态是干净的,但是当您推送时,它会推送到主控状态。听起来你在 master 中有一些未推送的提交所以 git push 也简单地推送了 master。