我可以推送在分离HEAD状态下进行的提交吗? [英] Can I push a commit made in detached HEAD state

查看:181
本文介绍了我可以推送在分离HEAD状态下进行的提交吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用git我想进入分离的HEAD状态并创建一个新的提交。然后,我想创建一个标签,并将分离的提交和标签都推送到远程仓库。这可能吗?



如果我在本地回购中创建分离的提交并创建标签,那么我可以检出标签以恢复到该状态。我想与远程repo分享,以便其他用途可以克隆repo并签出标签并达到相同的状态。



我想要的原因这是因为构建过程需要捕获文件中的构建编号,但我不想将其提交给正在进行开发的分支。我希望提交是分开的,但也希望捕获提交并对其进行标记,以便任何人都可以签出构建中包含的标记和文件。是否推荐将提交推送到不同的分支,比如说build?

解决方案

是的,this-bythisI意味着主要问题,你可以推送一个带标签的但不包含分支的提交吗? - 完全没问题。请注意, git push 通过调用其他一些Git(例如,ssh:// ...或https:// ...通过Internet调用另一个Git如果需要的话提交一些提交,然后再问其他的Git:请设置一个引用名称来指向某个特定的提交。



<因为你有一个标签,你可以要求其他Git请设置相同的标签。假设遥控器被命名为 origin (通常是这样):

  git push origin< tag> 

您可以拼出全名 refs / tags / 标记 ,如果需要的话。如果标签名称很容易与分支名称区分开来(例如,标签是 v2.x 而分支从不以 v 开头)它不会被需要(但它可能仍然是明智的一般)。

如果你没有标签,你仍然可以这样做,但你会必须提供其他Git a 名称。要做到这一点,你可以这样做:

  git push origin HEAD:refs / heads / newbranch 

或者:

  git push origin HEAD:refs / tags / newtag 

棘手的问题在于,不知道他们是否已经有分支 newbranch 或标记 newtag 。如果你自己设置了一个标签,并且一直从它们那里取得标签,那么你可能有一个好主意 - 当然不是保证 - 它们也没有标签。



请注意,如果他们 do 具有该名称,并且有礼貌地要求他们将其名称改为指向其他提交,则他们可能会拒绝。这是当你看到被拒绝推送错误。你可以命令它们(在refspec中使用 git push --force + >前缀语法),但通常不是正确的方法,再加上他们仍然可以拒绝(该部分取决于谁控制其他Git)。


Using git I would like to go into detached HEAD state and create a new commit. I'd then like to create a tag and push both the 'detached commit' and the tag to the remote repo. Is this possible?

If I create the detached commit in my local repo and create a tag then I can checkout the tag to get back to that state. I'd like to share that with the remote repo so that other uses can clone the repo and checkout the tag and get to that same state.

The reason I want to do this is because the build process needs to capture the build # in a file but I don't want to commit that to the branch where development is ongoing. I want the commit to be separate, but also want to capture the commit and tag it so that anyone can checkout the tag and the files that are included in the build. Is it recommended to push the commit to different branch, say "build"?

解决方案

Yes, this—by "this" I mean the main question, "can you push a tagged but not branch-contained commit?"—is perfectly fine. Note that git push works by calling up some other Git (e.g., ssh://... or https://... call up the other Git over the Internet-phone), delivering some commit(s) if necessary, and then asking that other Git: "please set a reference name to point to some specific commit(s)".

Since you have a tag, you can ask that other Git to please set the same tag. Assuming the remote is named origin (as it typically is):

git push origin <tag>

You can spell out the full name, refs/tags/tag, if needed. If tag names are easily distinguished from branch names (e.g., tags are v2.x and branches never start with v) it won't ever be needed (but it might still be wise in general).

If you did not have a tag, you could still do it, but you would have to provide the other Git a name. To do that, you would do something like:

git push origin HEAD:refs/heads/newbranch

or:

git push origin HEAD:refs/tags/newtag

The tricky bit here is that during the push, you have no idea whether they have a branch newbranch or tag newtag already. If you've set a tag yourself, and have also been fetching from them all along, you probably have a good idea—not a guarantee, of course—that they do not have that tag yet either.

Note that if they do have that name, and you politely request that they change their name to point to some other commit, they may refuse. This is when you see rejected errors from push. You can command them (using git push --force or the + prefix syntax on a refspec), but that's usually not the right way to go, plus they can still refuse (that part is up to whoever controls the other Git).

这篇关于我可以推送在分离HEAD状态下进行的提交吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆