When will I see this message?
When you lập cập git merge --ff-only
or git pull --ff-only
, and the branch or commit you are trying to lớn merge is not based off your current branch—its history has somehow forked from yours.
git pull
can have defaults phối in the configuration, sánh you can also see this if you ran a plain git pull origin
, and your config has pull.ff = only
.
To kiểm tra your config: lập cập git config pull.ff
or git config --show-origin pull.ff
(git merge
has a similar merge.ff
option)
How can I see what doesn't work?
To view the history of both your branch and the target branch, you can use:
git log --graph --oneline HEAD
If you didn't explicitly type a branch name (e.g: git merge --ff-only
or git pull --ff-only
), git
defaults to lớn "the upstream branch of your active branch" -- it often is origin/mybranch
. A way to lớn reference that branch from the command line is @{u}
:
git log --graph --oneline HEAD @{u}
# For Powershell users: @{...} is an operator, you will need to lớn quote "@{u}"
git log --graph --oneline HEAD "@{u}"
You should see the divergence between your current branch and the target branch.
See also "More git log
options" below.
What can I tự to lớn fix this?
This depends on the result you want to lớn reach, and what you see in the history above.
You may want to lớn rebase your commits on top of target commit:
git rebase
# To rebase on top of your mặc định upstream:
git rebase # The same as 'git rebase @{u}'
You may want to lớn lập cập an actual merge instead of only allowing fast forwards:
git merge
git merge # The same as 'git merge @{u}'
Or anything that suits your needs:
- cherry-pick some of your commits on top of the remote branch,
- use
git rebase -i
, - merge the other way around...
How can I avoid this when I lập cập git pull
?
If you have phối --ff-only
as a mặc định (e.g: if git config pull.ff
returns only
), you can override this mặc định on a one off basis by explicitly providing a command line flag:
git pull --rebase # Rebase on top of fetched branch, rather kêu ca merge it.
git pull --ff # Run a normal merge
# (note: you *will* have a merge commit in your history)
If you want to lớn change that mặc định to lớn some other value:
# Remove that mặc định value, allow normal merges when pulling
git config --global --unset pull.ff
# Run `git pull --rebase` by default
# Note: you still need to lớn lập cập 'git config --global --unset pull.ff'
git config --global pull.rebase true
More git log
options
To see the differences between two branches in your terminal:
git log --oneline --graph a b
will show you the complete histories of a
and b
combined together.
If you want to lớn see the history of a
and b
since they forked:
git log --oneline --graph --boundary a...b
# a...b (3 dots) : Means 'symmetric difference' in git log
# --boundary : Will show the commit that was at the fork point
# without this option, the two histories will be
# printed one below the other
If you want to lớn hide side branches -- for example, if you want to lớn view git log my/branch...master
, but you don't want to lớn view the details of all pull requests that got merged in master
:
git log --oneline --graph --boundary --first-parent a...b
# --first-parent : On merge commits, only follow the first parent
Many graphical frontend to lớn Git (Git Extensions, TortoiseGit, gitk, etc.) have ways to lớn activate these options when you view your repositories history.
Look for the checkboxes in your GUI, and for fields where you may type a...b
or HEAD...@{u}
.
If you intend to lớn use some of these commands on a regular basis, phối an alias for them:
# Example: show HEAD vs @{upstream} log
git config --global alias.whatsup 'log --oneline --graph --boundary HEAD...@{u}'
# You can now run:
git whatsup