Linux command
git-merge 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Merge branch into current
git merge [branch-name]
Merge with commit message
git merge [branch] -m "[message]"
Merge without fast-forward (preserve topology)
git merge --no-ff [branch]
Only allow fast-forward, otherwise fail
git merge --ff-only [branch]
Squash merge (single staged changeset, no merge commit)
git merge --squash [branch]
Favor our or their side on conflicts
git merge -X ours [branch]
Abort or continue an in-progress merge
git merge --abort``` / ```git merge --continue
说明
git merge incorporates changes from the named commits (typically branch tips) into the current branch. It is also invoked internally by git pull to integrate fetched changes. A fast-forward merge simply advances the current branch pointer to the merged commit without creating a new commit; `--no-ff` forces a merge commit to preserve branch topology, while `--ff-only` refuses the merge unless it is a fast-forward. Squash merges (`--squash`) collapse all incoming changes into a single staged changeset without recording a merge commit. When textual conflicts occur, conflict markers are written into affected files; resolve them, `git add` the files, then run `git merge --continue` (or `git commit`). The default strategy is ort ("Ostensibly Recursive's Twin"), which replaced the older recursive strategy in Git 2.33 and handles three-way merges with rename detection.
参数
- --no-ff
- Always create a merge commit, even when fast-forward is possible.
- --ff-only
- Refuse to merge unless the current HEAD can be fast-forwarded.
- --squash
- Produce working tree/index as if a real merge happened, but do not make a commit.
- --no-commit
- Perform the merge but stop before creating a commit (allows inspection).
- -m _MESSAGE_
- Set the commit message for the merge commit.
- -e, --edit
- Invoke the editor to refine the auto-generated commit message.
- --abort
- Abort the current conflict resolution and reconstruct the pre-merge state.
- --continue
- Continue the merge after conflicts have been resolved.
- --quit
- Forget about the current merge in progress without restoring the pre-merge state.
- -s _STRATEGY_, --strategy=_STRATEGY_
- Select merge strategy: `ort` (default), `resolve`, `octopus`, `ours`, or `subtree`.
- -X _OPTION_, --strategy-option=_OPTION_
- Pass a strategy-specific option (e.g., `ours`, `theirs`, `ignore-all-space`, `find-renames`).
- --autostash
- Automatically stash and restore local changes around the merge.
- --allow-unrelated-histories
- Merge histories that do not share a common ancestor.
- --verify-signatures
- Require a valid GPG signature on the side branch tip.
- -S_KEYID_, --gpg-sign=_KEYID_
- GPG-sign the resulting merge commit.
- --log=_N_
- Include one-line descriptions of the merged commits in the merge commit message.
- --help
- Display help information.
FAQ
What is the git-merge command used for?
git merge incorporates changes from the named commits (typically branch tips) into the current branch. It is also invoked internally by git pull to integrate fetched changes. A fast-forward merge simply advances the current branch pointer to the merged commit without creating a new commit; `--no-ff` forces a merge commit to preserve branch topology, while `--ff-only` refuses the merge unless it is a fast-forward. Squash merges (`--squash`) collapse all incoming changes into a single staged changeset without recording a merge commit. When textual conflicts occur, conflict markers are written into affected files; resolve them, `git add` the files, then run `git merge --continue` (or `git commit`). The default strategy is ort ("Ostensibly Recursive's Twin"), which replaced the older recursive strategy in Git 2.33 and handles three-way merges with rename detection.
How do I run a basic git-merge example?
Run `git merge [branch-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --no-ff do in git-merge?
Always create a merge commit, even when fast-forward is possible.