Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Git merge command usage


May 25, 2021 Git



Git merge is a command that is used more frequently in Git and is primarily used to add (merge) two or more development histories together. This article brings you a common use of git merge commands.


There are three syntaxes for git merge:

git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
    [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
    [--[no-]allow-unrelated-histories]
    [--[no-]rerere-autoupdate] [-m <msg>] [<commit>…?]
git merge --abort
git merge --continue


git merge purpose

The git-merge command is an operation that is used to merge from the specified commit(s) to the current branch.

Note: The specified commit(s) here refers to starting with these historical commit nodes until the current separation.

1, for git-pull, to integrate changes in another code repository (i.e., git pull s git fetch s git merge)

2, for merging from one branch to another


Suppose the historical node in the following image exists and the current branch is "master":

Git merge command usage

The git merge topic then re-re-states the node (i.e., the A B C node of the topic branch) that is separated after the two nodes (E nodes) on the master branch until the current commit node (C node) of the topic branch is located at the top of the master branch. A new node that records the results of the merge is also created along the master branch and the topic branch, which has information that the user describes the merge changes.

That is, the H node in the figure below, the C node and the G node are the parent nodes of the H node.

Git merge command usage


git merge <msg> HEAD <commit>... C ommand

The command exists for historical reasons and should not be used in the new version, and should be used by git merge -m;msg> slt;commit&gt.... M ake an alternative


git merge --abort command

The command is used only if the merge results in a conflict. g it merge --abort will abandon the merge process and attempt to rebuild the pre-merge state. H owever, if there are files without commit at the beginning of the merge, the git merge --abort will not be able to reproduce the pre-merge state in some cases. ( Especially if these un commit files will be modified during the merge process)

Warning:

Running git-merge with a large number of uncommitted files can easily get you into trouble, which will make it difficult for you to fall back in a conflict. Therefore, it is highly undringed to have un commit files when using git-merge, and it is recommended that you staging these un commit files with the git-stash command and restoring them with git stash pop after resolving the conflict.


These are some common uses of the Git merge command, which I hope will help you. To learn more about Git commands, click on: Git Common Command Quick Checker