Is it possible to push a commit which is not in any branch in git?

谁都会走 提交于 2019-12-12 12:24:41

问题


Locally I can commit without any branch active, i.e. after checking out to a commit but not a branch. Is it possible to push this commit which is not in any branch to remote?

EDIT: I'm just wondering theoretically how would git handle pushing a "no-branch" or is pushing only possible with branches.


回答1:


When you do

git push <remote> <source>:<destination>

The <source> can be a commit, yes.

The <destination>, however, is a bit more tricky. Take it from the doc :

It’s possible to push any type of object to any namespace outside of refs/{tags,heads}/. In the case of tags and commits, these will be treated as if they were the commits inside refs/heads/ for the purposes of whether the update is allowed.

So basically, you mostly push only to remote branches, but yes you can push commits, as long as moving from their current ref to the one you're pushing is a fast-forward merge.



来源:https://stackoverflow.com/questions/55130311/is-it-possible-to-push-a-commit-which-is-not-in-any-branch-in-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!