git push https://heroku:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cb8d4d9ced3d7c9c3ddccd5c3d7d9c5dcfbf5e8b2f4f9eef3f7e9b2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>/$HEROKU_APP_NAME_PRODUCTION.git HEAD
和
git push https://heroku:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cce884899e838799938d9c85938789958caba5b8e2a4a9bea3a7b9e2afa3a1" rel="noreferrer noopener nofollow">[email protected]</a>/$HEROKU_APP_NAME.git HEAD:master
看起来 HEAD:master 能够覆盖 .gitignore 文件,而 HEAD 不能。
最佳答案
差异在于远程服务器上的目标分支。
假设您坐在分支 foobar
上。
git checkout foobar
..workwork..
git push origin HEAD
HEAD
当前本地分支的最新版本。因此,在本例中它的意思是foobar
。因此,此命令将简单地将 foobar 发送到远程服务器。在远程服务器上,它将更新/覆盖与您发送的分支“匹配”*)的分支。通常,这意味着发送 foobar
as foobar
。这里没有什么惊喜。
另一方面
git checkout foobar
..workwork..
git push origin HEAD:master
明确指示 git 将您的 HEAD 作为 master 发送。这意味着,它会将您最近的 foobar
作为远程服务器上的 master
发送到远程服务器。就是这样,正是这样。您的本地master
不会改变并且保持不变。远程foobar
,如果存在的话,不会改变。但是,远程 master
现在将与本地 foobar
*) 客户端(本地端)决定在远程端选择哪个分支。本地分支和远程分支之间的默认映射保存在您的 .git/config 文件中。绝对有可能让你的本地分支aaa
自动发送到远程aaa
或远程bbb
,所以事实上我无法告诉你具体在哪里将 git push origin xxxx
推送 xxxx 分支 - 这取决于映射 - 您可以通过 --set-upstream
或仅编辑配置文件来更改它们。另一方面,git push origin xxx:yyy
始终意味着:将 x 作为 y 发送。
至于 .gitignore
部分 - 它没有任何关系。 pull 或推都没有任何.gitignore
。 Git-ignore 不会阻止您将任何内容推送到任何地方。它仅帮助您不提交不需要的文件。即使在这种情况下,它也不会阻止您,因为您始终可以通过 git add -f 添加任何文件,并且这些文件将像普通文件一样在推送期间发送到任何 Remote (它们,事实上,是)。
请注意,您显示的这 2 个命令使用不同的存储库:
...git.heroku.com/$HEROKU_APP_NAME_PRODUCTION.git ...git.heroku.com/$HEROKU_APP_NAME.git
也许这就是让你误以为 git-ignore 会带来改变的原因?
关于git - HEAD :master and HEAD? 和有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51155656/