git推送一个不属于任何分支的提交

时间:2015-06-05 05:23:11

标签: git

我有一个commit-id,目前它不属于任何分支。它有一个标签。如何将此提交推送到服务器?

git show 2.0.rc10
tag 2.0.rc10
Tagger: ....
Date:   Fri Mar 29 13:38:55 2013 -0700
Release 2.0.rc10;  merged 
commit f1186bfeb938081f9d57f8ac20667329b1c53111
跑步时

git branch -r --contains f1186bfeb938081f9d57f8ac20667329b1c53111

没有输出。

如何将此提交推送到服务器?

git push origin 2.0.rc10
remote: Tag '2.0.rc10' references unknown objects. Push commits before tags.
To 
 ! [remote rejected] 2.0.rc10 -> 2.0.rc10 (pre-receive hook declined)
error: failed to push some refs to 'remote'

3 个答案:

答案 0 :(得分:1)

您的问题不是Git,而是服务器上的预接收挂钩,显然检查提交是否被分支引用。

显然,解决方案是首先推动您的分支机构。我不确定为什么你会想要一个没有分支的标签。

答案 1 :(得分:0)

有问题的提交需要属于某个分支,以便您将其提交到远程存储库。假设您希望提交的分支称为yourbranch,那么以下应该可以解决这个问题:

git checkout yourbranch      # checkout the desired branch
git merge f1186bfe           # merge in the single commit
git push origin yourbranch   # push the branch out (with new commit) to the remote

您可能需要解决合并冲突。你应该确定你真的想要这个提交。您可以使用以下方法进行检查:

git show f1186bfe

您可以确保所需的标记仍在提交中:

git show 2.0.rc10

验证SHA-1哈希是否与您要保存的提交匹配,然后通过以下方法将标记推送到远程:

git push origin 2.0.rc10

答案 2 :(得分:0)

git push origin 2.0.rc10

实际上是推送你的提交的命令。由于标记2.0.rc10引用了提交,因此它被推送没有问题。

你的错误出现在遥控器之前使用你发送的内容时,拒绝它(pre-receive hook declined)。你需要修改你的预接收挂钩或推送你的挂钩接受的东西。 More info about hooks

一些测试

重新创造OP的情况:

git checkout --orphan orphan_branch
git commit -am "stray commit"
git tag -a 2.0.rc10 -m "2.0.rc10"
git checkout master
git branch -D orphan_branch

迷路提交:

git show 2.0.rc10
tag 2.0.rc10
Tagger: ...
Date:   Fri Jun 5 11:41:11 2015 +0200

2.0.rc10

commit 78e06b3a4841f88c1737ab8986fd6f3d753e1735
Author: ...
Date:   Fri Jun 5 11:41:00 2015 +0200

    stray commit

showing the stray commit

推送:

git push origin 2.0.rc10
Username for ...
Password for ...
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 305 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To ...
 * [new tag]         2.0.rc10 -> 2.0.rc10

因此,提交被推送并且标签在遥控器中创建,因为我没有预先接收挂钩,所以它被推送没有问题。