git - "debug"分支,合并"fix"分支而不"debug"

Jak*_* M. 6 git

我有一个master需要调试的错误分支.为此,我想插入一堆调试程序(例如,打印变量),指出错误并应用修复程序.稍后,我想将修复程序合并到master分支中,但我不想跳过调试更改.

# create debug branch
git checkout -b debug

# ...
# edit sources and add debug prints
# ...

# commit debug changes
git commit --all

# create branch for the fix
git checkout -b fix
Run Code Online (Sandbox Code Playgroud)

现在做正确的修复和提交

git commit --all
Run Code Online (Sandbox Code Playgroud)

master分公司......

git checkout master
Run Code Online (Sandbox Code Playgroud)

...并在没有调试更改的情况下合并修复程序

git merge fix # <-- wrong, will merge debug changes as well
Run Code Online (Sandbox Code Playgroud)

如何合并fix没有debug

GoZ*_*ner 8

您正在寻找的是'git rebase'的'on'选项(请参阅'git help rebase').从你描述的将是:

git rebase --onto master debug fix
Run Code Online (Sandbox Code Playgroud)

这实际上是在master处重新生成(从'fix'到'debug')提交.你仍然有修复分支.要完成返工,请跟进:

git checkout master
git merge fix
Run Code Online (Sandbox Code Playgroud)