Git 脑子乱了?

标签 git git-push git-remote

在分支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://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99eceafcebd9eceafcebb7faf6f4" rel="noreferrer noopener nofollow">[email protected]</a>/home/user/private/repos/user_hub.git
  Push  URL: ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="295c5a4c5b695c5a4c5b074a4644" rel="noreferrer noopener nofollow">[email protected]</a>/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分支:master。怎么了?

问题/疑问

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

更新

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

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

#!/bin/sh

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

case " $1 " 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 " $1 " 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://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deabadbbac9eabadbbacf0bdb1b3" rel="noreferrer noopener nofollow">[email protected]</a>/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

更新 2: 这个问题似乎已经解决了,但据我所知,我没有采取任何措施来“解决”它。 :s 不过,如果有人想澄清是否有问题,或者为什么这可能是一个问题,请告诉我。非常感谢。

最佳答案

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

阅读发行说明的第一段: 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。听起来您在 master 中有一些未推送的提交,因此 git push 也只是推送了 master 。

关于Git 脑子乱了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30308642/

相关文章:

git - Cygwin 和 Git : getting "fatal: error in line 1:"

git - Git 中是否推送了远程地址?

eclipse - 如何在Egit中设置远程跟踪分支?

git - 将上游 git 更改与挂起的 pull 请求 merge

windows - 如何在 Windows 上将 svn 存储库转换为 git

git - 使用 git add -A 后,.gitignore 被跟踪

git - 无法推送到远程 Git 存储库 - 一切都是最新的

git推送问题: Repository not found

git - 如何删除远程裸存储库分支上的提交?

linux - 在 GitHub 上添加了 BitBucket 存储库作为远程版本