发现问题
今日在Linux环境下使用使用git将本地仓库中的内容推送到远程仓库时,发现了一个问题🔍
完整的错误日志
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
- 说是
warning: push.default is unset; its implicit value is changing in Git 2.0
即push.default未设置,因为是头一次在Linux环境下使用git上面云端,所以就想到可能是有什么东西没有配置 - 阅读了一下给出的错误提示,应该是可以使用我下面框起来的两行命令,所以就在命令行执行了一下这两行命令
- 然后再去【git push】的时候就不会出现上述的错误警告了,那说明这个问题已经得到解决了,但非常疑惑这是为什么,于是就查询了一些资料去研究了一下
资料查询
simple means git push will push only the current branch to the one that git pull would pull from, and also checks that their names match. This is a more intuitive behavior, which is why the default is getting changed to this.
匹配意味着【git push】会将所有本地分支推送到远程上同名的分支。这使得你很容易不小心推到你不想推的树枝
simple means git push will push only the current branch to the one that git pull would pull from, and also checks that their names match. This is a more intuitive behavior, which is why the default is getting changed to this
simple意味着将只将当前分支推送到git pull将从中拉出的分支,并检查它们的名称是否匹配。这是一个更直观的行为,这就是为什么默认值会更改为这个
- 这个警告是在
Git 1.7.11
中引入的,同时还有simple推送方式.问题是当前的默认值matching会导致没有经验的用户在某些分支机构位于其远程等价物后面时强制推送,因为分支机构根本不是最新的.最终的结果是他们最终倒闭分支并可能失去他们的工作或其他人的工作. - 该simple模式是作为一种新push.default行为引入的,并将成为Git 2.0中的默认模式
解决问题
解决方案1:使用新版的shell
- 关闭运行旧版本git的shell并使用新版本
解决方案2:修改默认设置
- 摆脱消息的方法是设置push.default.要获得新行为,请使用:
git config --global push.default simple
- 要获取Git的默认行为但没有警告消息,请使用:
git config --global push.default matching
———————————————
2023年2月24日晚11点。遇此问题,顺手记录