git - 是否使用 git push --tags 指定 refspec 的区别
问题描述
我偶然发现了这个相当晦涩的问题,使用两个命令git push --tags
和git push --tags origin master
. 在以下情况下,它们的行为不同:
初始情况
我正在尝试将新创建的标签git tag test
(如图:
Remote [master] (one commit ahead):
A ----- B ----- C ---- D
Local [master] (one commit behind):
A ----- B ----- C
(tag:test)
问题
git push --tags
正在按预期工作:
Total 0 (delta 0), reused 0 (delta 0)
To https://remote.gitrepo.com/path/to/project
* [new tag] test14 -> test14
git push --tags origin master
被拒绝和错误:
Total 0 (delta 0), reused 0 (delta 0)
To https://remote.gitrepo.com/path/to/project
* [new tag] test15 -> test15
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://remote.gitrepo.com/path/to/project'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
问题
为什么要git push --tags origin master
尝试将某些东西从标签中推开?我在问为什么命令试图将分支推送到远程而不是为什么它被拒绝
解决方案
我在问为什么命令试图将分支推送到远程而不是为什么它被拒绝,
因为 git push 将推送新的提交和(使用--tags)新标签。
- C 已经被推了,所以没有什么可以推到那里的
- 新标签被推送。
在第二种情况下,您试图将远程主分支(位于 D)重置为 C(除了推送标签)。
推荐阅读
- javascript - 组件销毁后如何删除 ViewEncapsulation.None
- c# - Dynamics 365 - 为“审计”实体注册“创建”步骤
- lua - (LUA)我有什么办法可以剪切消息并将其保存在变量中?
- jenkins - jenkins 无法获取列表
- azure - 如何使用 ReadyApi 配置 Azure IOT 中心
- java - 为什么我的无效模式没有引发 PatternSyntaxException?
- java - JavaFX/Mac:当我将 useSystemMenuBar 设置为 true 时,系统菜单变得无响应
- vba - 点击确定按钮
- python - 了解 Django 3.1 中的模型权限
- android - 'react-native-mathjax' 不呈现单个反斜杠