首页 > 解决方案 > 合并时如何使用 GitPython 使用“--no-ff --no-commit”?

问题描述

当我使用命令行 git merge 和 --no-ff --no-commit 工作正常。但是使用 GitPython 我无法做到。

可能是我没有为使用 GitPython 的以下等效操作找到正确的文档或论坛。

我错过了什么吗?

命令行:

git merge --no-ff --no-commit "<TAG Name> or <Feature branch>"

GitPython:

print(f"Merging from tag '{input_tag}' into 'master'...")
repo = Repo(constants.git_clone_local_path)
repo.git.checkout('master')
repo.git.pull()
repo.git.merge(f'--no-ff --no-commit {input_tag}')
# repo.git.merge(f'{input_tag}', no_ff=True)
print(repo.git.status())
print('Done')

Python给出以下错误

cmdline: git merge --no-ff --no-commit test_tag
stderr: 'error: unknown option `no-ff --no-commit test_tag'
usage: git merge [<options>] [<commit>...]
or: git merge --abort
or: git merge --continue

-n                    do not show a diffstat at the end of the merge
--stat                show a diffstat at the end of the merge
--summary             (synonym to --stat)
--log[=<n>]           add (at most <n>) entries from shortlog to merge commit message
--squash              create a single commit instead of doing a merge
--commit              perform a commit if the merge succeeds (default)
-e, --edit            edit message before committing
--cleanup <mode>      how to strip spaces and #comments from message
--ff                  allow fast-forward (default)
--ff-only             abort if fast-forward is not possible
--rerere-autoupdate   update the index with reused conflict resolution if possible
--verify-signatures   verify that the named commit has a valid GPG signature
-s, --strategy <strategy>
                      merge strategy to use
-X, --strategy-option <option=value>
                      option for selected merge strategy
-m, --message <message>
                      merge commit message (for a non-fast-forward merge)
-F, --file <path>     read message from file
-v, --verbose         be more verbose
-q, --quiet           be more quiet
--abort               abort the current in-progress merge
--quit                --abort but leave index and working tree alone
--continue            continue the current in-progress merge
--allow-unrelated-histories
                      allow merging unrelated histories
--progress            force progress reporting
-S, --gpg-sign[=<key-id>]
                      GPG sign commit
--overwrite-ignore    update ignored files (default)
--signoff             add Signed-off-by:
--verify              verify commit-msg hook

标签: python-3.xgitpython

解决方案


这应该工作

git.merge('args', no_ff=True)

用你的论点替换'args',比如你的分支......


推荐阅读