Open dorawyy opened 6 years ago
#2
git checkout mt1
git commit test26_merge_test -m "mt1: x=1"
#3
git checkout mt2
git commit test26_merge_test -m "mt2: z=1"
#4
git checkout mt1
git commit test26_merge_test -m "mt1: x=2"
#5
git checkout mt2
git commit test26_merge_test -m "mt2: z=2"
The project status is:
git checkout mt1
git merge mt2
git checkout mt1
git merge mt2
Will be an auto three-way merging, as there is no conflict
git merge mt2 --no-commit
git checkout mt1
git merge mt2 --no-commit
--no-commit
param will combine all changes, simulate there is conflict when merging, then ask users to manually save commit; Note that when potential conflict, all changes will be saved in working tree (while when no conflict, all changes will be saved in index)
git merge mt2 --squash
git checkout mt1
git merge mt2 --squash
--squash
will squash all commits from the other branch into 1 single commit, then apply to current branch
Resolve the conflict
Then manually commit, but the commit is a normal commit ( with only 1 parent) (The automatically filled-in message of the squashed commit)
Here is the details about the commit:
--ff
& --no-ff
& --ff-only
--ff-only
As the merge here is not a fast-forward merge, with --ff-only
, no merge should happen
git checkout mt1
git merge mt2 --ff-only
--ff
& --no-ff
Merge mt1
to mt12
, which should be a fast-forward merge
git checkout mt2
git merge mt1 --no-ff
Create another commit on mt2
, which created a new file test26_mt2
, to test if mt1
can receive the file when using different merging options;
git checkout mt1
git merge mt2
Yes, able to see everything
--no-commit
git checkout mt1
git merge mt2 --no-commit
Yes, everything in index
--squash
git checkout mt1
git merge mt2 --squash
Yes, everything in working dir
#2
git checkout mt3
git commit test26_merge_test -m "mt3:x=1"
#3
git checkout mt4
git commit test26_merge_test -m "mt4:z=1"
#4
git checkout mt3
git commit test26_merge_test -m "mt3:y=1"
#5
git checkout mt4
git commit test26_merge_test -m "mt4:y=2,z=2"
git merge mt4
git checkut mt3
git merge mt4
Will have conflict that need to be resolved
Fix the conflict, then merge
git merge mt4 --no-commit
git checkout mt3
git merge mt4 --no-commit
--no-commit
param will combine all changes, simulate there is conflict when merging, then ask users to manually save commit
Then, fix the conflict, then continue merge
git merge mt4 --squash
git checkout mt3
git merge mt4 --squash
Thus, there is still only one commit. In other words, all commits from the other branch are squashed into one normal commit on current branch (with only one parent)
Create another commit on mt2, which created a new file test26_mt2, to test if mt1 can receive the file when using different merging options;
git checkout mt3
git merge mt4
Yes, updated in working tree
--no-commit
git checkout mt3
git merge mt4 --no-commit
Yes, saved in working tree, same as normal merge
--squash
git checkout mt3
git merge mt4 --squash
Yes, saved in woking tree, same as option1 and 2
After mt2
is merged to mt1
, mt1
is a commit ahead of mt2
, now, try:
git checkout mt2
git merge mt1
--ff
)Just move the head
pointer of mt2
one commit forward
git checkout mt2
git merge mt1
Regular fast-forward merge, move head
forward.
--no-commit
(--ff
)git checkout mt2
git merge mt1 --no-commit
As there is no commit created for fast-forward by default, thus no difference with this param only. Still moves the mt2
head
pointer 1 commit forward.
( same as normal fast-forward merge)
--squash
(--ff
)git checkout mt2
git merge mt1 --squash
Instead of performing a fast-forward commit, this will force the merge to create a squash commit on mt2
branch (which is a normal commit).
--commit
(--ff
)git checkout mt2
git merge mt1 --commit
The same as normal fast-forward merge.
--no-ff
git checkout mt2
git merge mt1 --no-ff
An explicit commit will be created for the merge, the original fast-forward merge is forced to become a three-way merge, with an explicit merge commit
--squash
& --no-ff
git checkout mt2
git merge mt1 --no-ff --squash
Error. This two param cannot be combined together.
--no-commit
& --no-ff
git checkout mt2
git merge mt1 --no-ff --no-commit
All changes are saved in the working tree, when commit, create a merge commit.
--ff-only
git checkout mt2
git merge mt1 --ff-only
Pass the assertion, performing a regular fast-forward merge commit
--squash
& --no-commit
git checkout mt2
git merge mt1 --squash --no-commit
same as --squash
only
git merge mt1 --squash
In the middle of squashing commits:
The version of the file is:
If git commit
, continue creating the squashed commit:
To test
git merge
configuration parametersgit merge
categorization --> #75References
git merge
- git documentationMerge process
(Took from git merge documentation) When it is not obvious how to reconcile the changes, the following happens:
HEAD
pointer stays the same.MERGE_HEAD
ref is set to point to the other branch head.HEAD
, and stage 3 fromMERGE_HEAD
(you can inspect the stages withgit ls-files -u
). The working tree files contain the result of the "merge" program; i.e. 3-way merge results with familiar conflict markers<<<
===
>>>
.HEAD
Synopsis
--commit
&--no-commit
--no-commit
With
--no-commit
perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge result before committing--squash
&--no-squash
--squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the
HEAD
, or record$GIT_DIR/MERGE_HEAD
(to cause the next git commit command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).--no-squash
With
--no-squash
perform the merge and commit the result. This option can be used to override--squash
.--ff
&--no-ff
&--ff-only
--ff
When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. This is the default behavior.
--no-ff
Create a merge commit even when the merge resolves as a fast-forward. This is the default behaviour when merging an annotated (and possibly signed) tag.
--ff-only
Refuse to merge and exit with a non-zero status unless the current
HEAD
is already up to date or the merge can be resolved as a fast-forward.Tools to use when resolving conflicts
(Took from git merge documentation)
git mergetool
Use a mergetool.
git merge tool
to launch a graphical mergetool which will work you through the merge.git diff
Look at the diffs.
git diff
will show a three-way diff, highlighting changes from both theHEAD
andMERGE_HEAD
versions.git log merge -p <path>
Look at the diffs from each branch.
git log --merge -p <path>
will show diffs first for theHEAD
version and then theMERGE_HEAD
version.git show :n:filename
Look at the originals.
git show :1:filename
shows the common ancestor,git show :2:filename
shows theHEAD
version, andgit show :3:filename
shows theMERGE_HEAD
version.Merge strategies
(reference: git merge documentation)
resolve
recursive
ours
theirs
patience
diff-algorithm=[patience|minimal|histogram|myers]
ignore-space-change
ignore-all-space
ignore-space-at-eol
renormalize
no-renormalize
no-renames
find-names[=<n>]
rename-threshold=<n>
subtree[=<path>]
octopus
ours
subtree