跳到主要内容

TS:从 Git 2.0 开始,push.default 的默认值将从 matching 改为 simple(已解决)

阅读需 4 分钟

TS:从 Git 2.0 开始,push.default 的默认值将从 matching 改为 simple-2024.6.2(已解决)

image-20240602204528076

目录

[toc]

1、问题现象

image-20240602203513108

[root@diy-index-home diy-index-home2.0]#git push
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

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 251 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To git@gitee.com:onlyonexl/diy-index-home2.0.git
e080c76..9f375e1 master -> master
[root@diy-index-home diy-index-home2.0]#git status
# On branch master
nothing to commit, working directory clean

2、gpt 回答

你在执行 git push 命令时,遇到了一个关于 push.default 配置项的警告。这个警告是提醒你,Git 2.0 版本对 push.default 的默认值进行了更改,并建议你明确设置该配置项以避免未来的混淆。以下是这个警告的详细解释和解决方法:

警告内容解释

  • push.default is unset:表示当前 Git 配置中没有设置 push.default 选项。
  • its implicit value is changing in Git 2.0 from 'matching' to 'simple':从 Git 2.0 开始,push.default 的默认值将从 matching 改为 simple

两种配置解释

  • matching:推送所有当前分支与远程仓库中具有相同名字的分支。这在某些情况下可能会推送不需要的分支。
  • simple推送当前分支到它的上游分支(通常是你从中拉取的分支)。这种方式更安全,并且是 Git 2.0 以后的推荐方式。

解决方法

你可以根据自己的需求选择合适的配置方式。以下是两个选项:

选项一:保持旧行为(matching)

如果你希望保持旧的行为,可以运行以下命令:

git config --global push.default matching

选项二:采用新行为(simple)

如果你希望采用推荐的新行为,可以运行以下命令:

git config --global push.default simple

推荐选择

推荐使用 simple 方式,因为它更安全,更符合直觉,并且适合大多数常见的使用情景。

以下是详细操作步骤:

  1. 打开终端或命令行。

  2. 运行以下命令之一,根据你的选择:

    • 保持旧行为:

      git config --global push.default matching
    • 采用新行为:

      git config --global push.default simple

设置完成后,你可以重新运行 git push 命令,警告信息将不再出现。

参考命令

你还可以通过以下命令查看当前的 Git 配置:

git config --list

这将列出所有的 Git 配置选项,帮助你确认 push.default 的设置情况。

希望这些信息能帮助你解决问题!

3、实际测试

  • 当前git版本
[root@diy-index-home diy-index-home2.0]#git version
git version 1.8.3.1
  • 查看当前的 Git 配置
[root@diy-index-home diy-index-home2.0]#git config --list
user.name=hg-diy-index-vm
user.email=2675263825@qq.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@gitee.com:onlyonexl/diy-index-home2.0.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

可以看到没配置,那就是默认的:matching

  • 本次自己配置为simple
[root@diy-index-home diy-index-home2.0]#git config --global push.default simple
  • 检查
[root@diy-index-home diy-index-home2.0]#git config --list
user.name=hg-diy-index-vm
user.email=2675263825@qq.com
push.default=simple ##本次配置后效果
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@gitee.com:onlyonexl/diy-index-home2.0.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

结束。

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码

x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号

《云原生架构师实战》

image-20230107215126971

🍀 个人博客站点

https://onedayxyy.cn/

image-20240530221922506

🍀 csdn

https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎

https://www.zhihu.com/people/foryouone

image-20230107215203185

最后

好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!