You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用bump2version创建自定义格式的版本标签?

Fixing Custom Version String Replacement with bump2version

I see the issue here—your command line arguments are conflicting with the rules defined in your .bumpversion.cfg file, leading to that messed-up version string in your CMakeLists.txt. Let's break down how to fix this.

The Problem with Your Current Command

When you added --search 1.0.17 --replace 1.0.17-testing to your command, you overrode the per-file search/replace patterns you already configured. Instead of looking for the full MVR_VERSION "{current_version}" string in CMakeLists.txt, bump2version started hunting for just 1.0.17 everywhere. This caused it to incorrectly replace parts of the existing line, resulting in that nested "MVR_VERSION "1.0.17"" mess.

The Correct Approach

You don't need the --search and --replace flags at all here. Your .bumpversion.cfg already has all the rules needed to properly update each file. Just specify the new custom version directly with --new-version, and bump2version will handle the rest using your existing config.

Step 1: Keep Your .bumpversion.cfg As-Is

Your current config is correct for targeting the right version strings in each file:

[bumpversion]
current_version = 1.0.17
[bumpversion:file:CMakeLists.txt]
search = MVR_VERSION "{current_version}"
replace = MVR_VERSION "{new_version}"
[bumpversion:file:VERSION.txt]
search = {current_version}
replace = {new_version}
[bumpversion:file:installer/mvr.iss]
search = #define MyAppVersion "{current_version}"
replace = #define MyAppVersion "{new_version}"

Step 2: Run the Simplified Command

Execute this command instead of your original one:

bump2version.exe --verbose --new-version 1.0.17-test-1

This tells bump2version to:

  • Use 1.0.17-test-1 as the new version
  • Follow the search/replace rules in your config for each file
  • Update current_version in .bumpversion.cfg to the new value automatically

What If You Need to Increment Test Versions?

If you later want to go from 1.0.17-test-1 to 1.0.17-test-2, just run the same command with the updated version string:

bump2version.exe --verbose --new-version 1.0.17-test-2

Alternatively, if you want to automate the test version increment, you could define a custom part in your config, but for one-off or ad-hoc custom versions, directly specifying --new-version is the simplest and most reliable approach.

Why This Works

By removing the conflicting --search and --replace flags, you let bump2version use the precise patterns you defined for each file. For CMakeLists.txt, it will find the exact line MVR_VERSION "1.0.17" and replace it with MVR_VERSION "1.0.17-test-1", which is exactly what you want.

内容的提问来源于stack exchange,提问作者Totte Karlsson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 21:03:12