From 48059e405028ebf8a09c5a9aede89dfb460cce98 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Dec 2013 12:47:25 +0000 Subject: [PATCH 1/2] pull: use merge-base --fork-point when appropriate Since commit d96855f (merge-base: teach "--fork-point" mode, 2013-10-23) we can replace a shell loop in git-pull with a single call to git-merge-base. So let's do so. Signed-off-by: John Keeping Signed-off-by: Junio C Hamano --- git-pull.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/git-pull.sh b/git-pull.sh index b946fd975..605e9575d 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -229,15 +229,7 @@ test true = "$rebase" && { test -n "$curr_branch" && . git-parse-remote && remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" && - oldremoteref="$(git rev-parse -q --verify "$remoteref")" && - for reflog in $(git rev-list -g $remoteref 2>/dev/null) - do - if test "$reflog" = "$(git merge-base $reflog $curr_branch)" - then - oldremoteref="$reflog" - break - fi - done + oldremoteref=$(git merge-base --fork-point "$remoteref" $curr_branch) } orig_head=$(git rev-parse -q --verify HEAD) git fetch $verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" || exit 1 From ad8261d21221d27638c75f47b39892db6f7972f6 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Mon, 9 Dec 2013 23:16:16 +0000 Subject: [PATCH 2/2] rebase: use reflog to find common base with upstream Commit 15a147e (rebase: use @{upstream} if no upstream specified, 2011-02-09) says: Make it default to 'git rebase @{upstream}'. That is also what 'git pull [--rebase]' defaults to, so it only makes sense that 'git rebase' defaults to the same thing. but that isn't actually the case. Since commit d44e712 (pull: support rebased upstream + fetch + pull --rebase, 2009-07-19), pull has actually chosen the most recent reflog entry which is an ancestor of the current branch if it can find one. Add a '--fork-point' argument to git-rebase that can be used to trigger this behaviour. This option is turned on by default if no non-option arguments are specified on the command line, otherwise we treat an upstream specified on the command-line literally. Signed-off-by: John Keeping Signed-off-by: Junio C Hamano --- Documentation/git-rebase.txt | 10 ++++++++++ git-rebase.sh | 19 +++++++++++++++++++ t/t3400-rebase.sh | 6 ++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 94e07fdab..2889be6bd 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -324,6 +324,16 @@ fresh commits so it can be remerged successfully without needing to "revert the reversion" (see the link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for details). +--fork-point:: +--no-fork-point:: + Use 'git merge-base --fork-point' to find a better common ancestor + between `upstream` and `branch` when calculating which commits have + have been introduced by `branch` (see linkgit:git-merge-base[1]). ++ +If no non-option arguments are given on the command line, then the default is +`--fork-point @{u}` otherwise the `upstream` argument is interpreted literally +unless the `--fork-point` option is specified. + --ignore-whitespace:: --whitespace=