If I want to update my local branch, say master
, to the remote branch gitlab/master
, I see two options:
The first operation can be achieved in my SmartGit GUI by right-click: merge
. The latter operation can be achieved by dragging the local branch marker to a new position.
Is there any technical difference between git merge --ff <commit>
and git reset <commit> --mixed
?
I admit that reset could also be used to move the local branch to another branch, which is not in the fast-forward way.
If the merge resolves as a fast-forward, there should be no differences, but if it's not the case:
git merge
, you will have a merge commit and all commit from both branches.git reset
, you will have only commits from gitlab/master
and no merge commit. The commits from master
absent from gitlab/master
will be uncommited (reset) but their content will be present in the working directory.You can try this yourself, with the follwing two scenari:
(Initialisation, common two both scenari, we use master
as gitlab/master
and branch1
as master
)
# Common commit
git init
echo a > a; git add .; git commit -m"a"
# Commit on branch1
git checkout -b branch1
git init
echo b > b; git add .; git commit -m"b"
# Second commit on master
git checkout master~1
echo c > c; git add .; git commit -m"c"
(Merge scenario)
git checkout branch1
git merge master
(Reset scenario)
git checkout branch1
git reset master
Note also that both options --ff
and --mixed
are default options and can be omitted.