[英]What is the difference between “git push origin HEAD:clean_up” and without HEAD?
What is the difference between 有什么区别
git push origin HEAD:clean_up
and 和
git push origin clean_up
What does HEAD
actually mean ? HEAD
究竟意味着什么?
HEAD
points to the last commit of the current branch. HEAD
指向当前分支的最后一次提交。 So if the current branch be clean_up
, then I would expect the following two commands to do the same thing: 因此,如果当前分支是
clean_up
,那么我希望以下两个命令执行相同的操作:
git push origin HEAD:clean_up
git push origin clean_up
I can think of one scenario where you might want to use something other than HEAD
when doing a git push
. 我可以想到一个场景,在执行
git push
时你可能想要使用除HEAD
以外的东西。 Suppose you checked out a certain branch branch
in detached HEAD
state. 假设您以分离的
HEAD
状态签出了某个分支branch
。 You made a few commits in it, and now you have decided that you want to push it out to repository as a new branch of its own. 你在其中做了一些提交,现在你已经决定将它作为自己的新分支推送到存储库。 However, you want to push out the branch from one commit before the last commit you made.
但是,您希望在上次提交之前从一次提交中推出分支。 In this case, you would take the following steps:
在这种情况下,您将采取以下步骤:
git checkout <SHA-1 of `branch` you want>
# make a few commits
git push origin HEAD~1:new_branch
This would push out branch
to the remote up to and including the previous commit you made. 这会将
branch
推送到远程,包括您之前的提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.