Re: git pull --rebase should use fast forward merge if possible
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 29, 2016, 16:32 UTC
- Message-ID
- <xmqqd1n0552i.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <OF95D98CB6.47969C1C-ONC1257FE1.0058D980-C1257FE1.0059986D@dakosy.de>
neuling@dakosy.de writes:
Show 11 quoted lines
> since I have added "pull.rebase=preserve" to my global configuration I > wonder why "git pull" also trys to rebase if a fast forward merge is > possible. > > A fast forward merge would speed up every pull if your local branch > contains no new commits and the remote branch is ahead. The result would > be the same. > > Is it possible to change the behavior of "git pull > --rebase=true|preserve|interactive" to use a fast forward merge if the > remote branch is ahead and the local branch contains no new commits?
Interesting. I do not think of a reason why we shouldn't.
If we were still working in scripted Porcelain, it would have been a five minute hack, perhaps like this.
contrib/examples/git-pull.sh | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/contrib/examples/git-pull.sh b/contrib/examples/git-pull.sh index 6b3a03f..3648040 100755 --- a/contrib/examples/git-pull.sh +++ b/contrib/examples/git-pull.sh @@ -358,6 +358,14 @@ fi if test true = "$rebase" then + if git merge-base --is-ancestor "$orig_head" "$merge_head" + then + # We can just fast-forward, as "git rebase --no-ff" + # is nonsense. + git merge --ff-only "$merge_head" + exit + fi + o=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref) if test "$oldremoteref" = "$o" then