]> git.ipfire.org Git - thirdparty/git.git/commit
merge: teach --autostash option
authorDenton Liu <liu.denton@gmail.com>
Tue, 7 Apr 2020 14:28:07 +0000 (10:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Apr 2020 16:28:02 +0000 (09:28 -0700)
commita03b55530ab844974b7058042a015fcfcd9e7a53
treebafe59f6e7bab8e6d37854fc7be2a85f71176425
parent804fe3155761e73c3dcc4e162ddb3ff560f16cd7
merge: teach --autostash option

In rebase, one can pass the `--autostash` option to cause the worktree
to be automatically stashed before continuing with the rebase. This
option is missing in merge, however.

Implement the `--autostash` option and corresponding `merge.autoStash`
option in merge which stashes before merging and then pops after.

This option is useful when a developer has some local changes on a topic
branch but they realize that their work depends on another branch.
Previously, they had to run something like

git fetch ...
git stash push
git merge FETCH_HEAD
git stash pop

but now, that is reduced to

git fetch ...
git merge --autostash FETCH_HEAD

When an autostash is generated, it is automatically reapplied to the
worktree only in three explicit situations:

1. An incomplete merge is commit using `git commit`.
2. A merge completes successfully.
3. A merge is aborted using `git merge --abort`.

In all other situations where the merge state is removed using
remove_merge_branch_state() such as aborting a merge via
`git reset --hard`, the autostash is saved into the stash reflog
instead keeping the worktree clean.

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Suggested-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 files changed:
Documentation/config/merge.txt
Documentation/git-merge.txt
Documentation/merge-options.txt
branch.c
builtin/commit.c
builtin/merge.c
builtin/rebase.c
parse-options.h
path.c
path.h
t/t3033-merge-toplevel.sh
t/t7600-merge.sh